spring源码附录(3)容器的基本实现
2017-04-17 09:55
495 查看
一、配置文件读取结构
spring对其内部使用到的资源实现了自己的抽象结构。该结构如下:spring使用(接口-抽象类-实现类-内部类)的模式实现各种类型文件的读取。
InputStreamSource作为其顶级接口,只定义一个方法:
InputStream getInputStream() throws IOException;
Resource接口抽象了所有Spring内部使用到的底层资源。对于不同来源的资源文件都有相应的Resource实现:
boolean exists(); boolean isReadable(); boolean isOpen(); URL getURL() throws IOException; URI getURI() throws IOException; File getFile() throws IOException; long contentLength() throws IOException; long lastModified() throws IOException; Resource createRelative(String relativePath) throws IOException; String getFilename(); String getDescription();
①文件:FileSystemResource
②class:CalssPathResource
③URL资源:UrlResource
④InputStream资源:InputStream
…
其中ServletContextResource来自Spring web模块。
ContextResource接口
其中只有定义了一个方法,获取相对与Context下的路径:
/** * Return the path within the enclosing 'context'. * <p>This is typically path relative to a context-specific root directory, * e.g. a ServletContext root or a PortletContext root. */ String getPathWithinContext();
其中classPathContextResource、ClassRelativeContextResource、FileSystemContextResource均是内部类实现,ServletContextResource
是单独实现。
相关文章推荐
- 【Spring源码分析系列】结构组成和容器的基本实现
- Spring 源码深入解析(1)之bean容器的基本实现(二)
- 【Spring源码分析系列】搭建Spring实现容器的基本实现
- spring源码解读(1)-容器基本实现
- 创建ApplicationContext与BeanFactory时的区别-Spring源码学习之容器的基本实现
- spring源码初步学习-容器(BeanFactory)基本实现
- spring源码--容器的基本实现
- Spring源码解析-容器的基本实现
- 创建ApplicationContext与BeanFactory时的区别-Spring源码学习之容器的基本实现
- 【Spring源码--IOC容器的实现】(五)Bean对象的创建
- 【Spring源码--IOC容器的实现】(一)Web容器的启动
- Spring源码解析:IoC容器的基本结构设计
- Spring源码学习之:模拟实现BeanFactory,从而说明IOC容器的大致原理
- Spring源码解析之IoC容器系列的设计实现(IoC容器系列概况)
- 2.1 Spring容器的基本实现--Spring源码深度解析
- spring源码 之1.1 容器基本用法以及功能分析
- 【Spring源码--IOC容器的实现】-- 综述
- Spring源码分析----IOC容器的实现(IoC容器的初始化过程(定位、载入解析、注册))
- Spring源码分析----IoC容器其他特性的设计与实现
- 1000行代码读懂Spring- 实现一个基本的IoC容器