spring源码附录(3)容器的基本实现

一、配置文件读取结构

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
是单独实现。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值