您的位置:首页 > 编程语言 > Java开发

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源码