spring的资源访问工具类
2016-02-04 01:00
489 查看
Spring设计了一个Resource接口,它为应用提供了更强大的访问底层资源的能力:
主要方法:
boolean exists()
boolean isopen()
url geturl()
File getFile()
inputStream getInputStream
具体实现类
byteArrayResource
classPathResource
fileSystemResource
inputStreamResource
UrlResource
为了访问不同类型的资源,必须使用相应的Resorce实现类,这是比较麻烦的,spring提供了一个强大的加载资源的机制,能够自动识别不同的资源类型。
资源类型地址前缀:
1:classpath classpath:com/jike/bean.xml;从类路径中加载资源classpath:和classpath:/是等价的。
2:File file:/com/jkle/bean.xml
3: http://http://www.jike
4: ftp:ftp://www.jkle.com/bean.xml
5:无前缀com/like/bean.xml
ant风格的匹配符
1.?:匹配文件名中的一个字符
2.* :匹配文件命中的任意字符
3.** :匹配多层路径
ant风格的资源路径示例:
1.Classpath:com/t*st.xml
2.File:D:/conf/*.xml
3.Classpath:com/**/test.xml
4.Classpath:org/springfranework/**/*.xml
主要方法:
boolean exists()
boolean isopen()
url geturl()
File getFile()
inputStream getInputStream
具体实现类
byteArrayResource
classPathResource
fileSystemResource
inputStreamResource
UrlResource
为了访问不同类型的资源,必须使用相应的Resorce实现类,这是比较麻烦的,spring提供了一个强大的加载资源的机制,能够自动识别不同的资源类型。
资源类型地址前缀:
1:classpath classpath:com/jike/bean.xml;从类路径中加载资源classpath:和classpath:/是等价的。
2:File file:/com/jkle/bean.xml
3: http://http://www.jike
4: ftp:ftp://www.jkle.com/bean.xml
5:无前缀com/like/bean.xml
ant风格的匹配符
1.?:匹配文件名中的一个字符
2.* :匹配文件命中的任意字符
3.** :匹配多层路径
ant风格的资源路径示例:
1.Classpath:com/t*st.xml
2.File:D:/conf/*.xml
3.Classpath:com/**/test.xml
4.Classpath:org/springfranework/**/*.xml
相关文章推荐
- spring IOC的理解
- java深入理解反射机制
- 《Netty in Action V5》-- 第1章 Netty与Java NIO APIS
- Java调用net的webservice故障排除
- Hello Java !
- 构建一个Struts2项目
- 2016/2/3 Head First Java 第五节/第六节小结
- Java正则表达式提取字符的方法实例
- Spring Security安全框架入门篇
- Spring Security安全框架入门篇
- Spring Security安全框架入门篇
- Spring Security安全框架入门篇
- java内存对象模型
- java中instanceof用法
- java设计模式之 适配器模式
- java 设计模式之 策略模式
- 使用jdk自带的webservice
- JavaWeb出现404一个很隐蔽的原因
- 【Clojure】Clojure与Java的互操作形式
- JAVA中的Jar