spring的资源访问工具类

来源:互联网 发布:mac电脑开机密码设置 编辑:程序博客网 时间:2024/06/07 06:13

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


1 0