Spring源码——Resource
来源:互联网 发布:吉林大学软件学院 编辑:程序博客网 时间:2024/05/09 05:07
Resource
定义
资源文件来自于classPath或者本地文件。
/**
* Interface for a resource descriptor that abstracts from the actual
* type of underlying resource, such as a file or class path resource.
*
* <p>An InputStream can be opened for every resource if it exists in
* physical form, but a URL or File handle can just be returned for
* certain resources. The actual behavior is implementation-specific.
*
基本方法
基本方法的单元测试以及输出
/**
* org.springframework.core.io.Resource test
* Created by jinglongjun on 2017/3/30.
*/
public class TestResource {
@Test
public void testResource() throws IOException {
Resource resource = new ClassPathResource("spring.xml");
System.out.println(resource.exists());
System.out.println(resource.getDescription());
System.out.println(resource.getURL().getPath());
}
}
输出结果:
true
class path resource [spring.xml]
/Users/jinglongjun/programe/workspace/spring/target/test-classes/spring.xml
Resouce继承关系
ClassPathResource
通过给定的ClassLoader或者ClassPath来加载资源。
/**
* Create a new {@code ClassPathResource} for {@code ClassLoader} usage.
* A leading slash will be removed, as the ClassLoader resource access
* methods will not accept it.
* @param path the absolute path within the classpath
* @param classLoader the class loader to load the resource with,
* or {@code null} for the thread context class loader
* @see ClassLoader#getResourceAsStream(String)
*/
public ClassPathResource(String path, ClassLoader classLoader) {
Assert.notNull(path, "Path must not be null");
String pathToUse = StringUtils.cleanPath(path);
if (pathToUse.startsWith("/")) {
pathToUse = pathToUse.substring(1);
}
this.path = pathToUse;
this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
}
0 0
- Spring源码——Resource
- Spring源码分析篇01——Resource
- spring resource源码讲解
- Spring入门——Resource
- spring源码解析-资源管理Resource
- spring——(5)Resource
- 深入Spring IOC源码之Resource
- Spring源码阅读之Resource接口
- 深入Spring IOC源码之Resource
- spring源码分析:resource资源定位一
- Spring源码之Resource加载源码解析(一)
- Spring源码之Resource加载源码解析(二)
- Spring源码之Resource加载源码解析(三)
- (七)Spring详解——资源Resource接口
- Spring @Resource
- Spring @Resource
- spring @Resource
- Spring @Resource
- spring之路
- Javascript数据结构算法之队列(舞伴分配,基数排序,模拟优先就诊病人)
- hdu 4611循环节 Balls Rearrangement
- 逆向iir滤波器的实现
- 【知识福利社】教你如何谈薪资,即将直播
- Spring源码——Resource
- Genealogical tree
- GhostScript命令参数详解
- Hibernate之路
- Spring源码——BeanFactory 注册bean
- Xlistview
- 分治法实现归并排序(JAVA实现)
- 金庸小说的模式
- Vim简单配置