方法
getInputStream
getFile
getURL
getDescription
exists
isOpen
Resource实现接口
UrlResource
对应前缀:getResource("http://localhost:8080/bean.xml")
ClassPathResource--
对应前缀:getResource("classpath:bean.xml")
FileSystemReource--还不如用File
对应前缀:getResource("file:bean.xml")
ServletContextResource--JSP不能直接访问WEB-INF下任何文件,可以通过这个访问
InputStreamResource
ByteArrayResource--字节数组 string.getBytes()
spring提供两个标记接口
ResourceLoader--获得一个Resource实例 getResource(String location)
ResourceLoaderAware--获得一个ResourceLoader获得一个ResourceLoader引用
由于ApplicationContext实现类实现了ResourceLoader接口,所以ApplicationContext可以直接
获得Resource,当使用ClassPathXmlApplicationContext实现时,使用的是ClassPathResource实现类,
有3个实现类
ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
XmlWebApplicationContext--ServletContextResource
当然!!!!也可以用不同前缀来制定
注入Resouces的bean,这个好用!!!!还可以路径解耦!!!!
getInputStream
getFile
getURL
getDescription
exists
isOpen
Resource实现接口
UrlResource
对应前缀:getResource("http://localhost:8080/bean.xml")
ClassPathResource--
对应前缀:getResource("classpath:bean.xml")
FileSystemReource--还不如用File
对应前缀:getResource("file:bean.xml")
ServletContextResource--JSP不能直接访问WEB-INF下任何文件,可以通过这个访问
InputStreamResource
ByteArrayResource--字节数组 string.getBytes()
spring提供两个标记接口
ResourceLoader--获得一个Resource实例 getResource(String location)
ResourceLoaderAware--获得一个ResourceLoader获得一个ResourceLoader引用
由于ApplicationContext实现类实现了ResourceLoader接口,所以ApplicationContext可以直接
获得Resource,当使用ClassPathXmlApplicationContext实现时,使用的是ClassPathResource实现类,
有3个实现类
ClassPathXmlApplicationContext
FileSystemXmlApplicationContext
XmlWebApplicationContext--ServletContextResource
当然!!!!也可以用不同前缀来制定
注入Resouces的bean,这个好用!!!!还可以路径解耦!!!!