spring resource

本文深入探讨了Spring框架中Resource接口及其发展历程,介绍了Resource的前生后世,并详细阐述了Resource辅助工具类ResourceUtils的功能及用途,同时展示了Resource的继承关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.resource的前生后世

  前生:public interface Resource extends InputStreamSource

public interface InputStreamSource {

    /**
     * Return an {@link InputStream}.
     * <p>It is expected that each call creates a <i>fresh</i> stream.
     * <p>This requirement is particularly important when you consider an API such
     * as JavaMail, which needs to be able to read the stream multiple times when
     * creating mail attachments. For such a use case, it is <i>required</i>
     * that each <code>getInputStream()</code> call returns a fresh stream.
     * @throws IOException if the stream could not be opened
     * @see org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
     */
    InputStream getInputStream() throws IOException;

}

后世:

2.Resource辅助工具类ResourceUtils

 1     /** Pseudo URL prefix for loading from the class path: "classpath:" */
 2     public static final String CLASSPATH_URL_PREFIX = "classpath:";
 3 
 4     /** URL prefix for loading from the file system: "file:" */
 5     public static final String FILE_URL_PREFIX = "file:";
 6 
 7     /** URL protocol for a file in the file system: "file" */
 8     public static final String URL_PROTOCOL_FILE = "file";
 9 
10     /** URL protocol for an entry from a jar file: "jar" */
11     public static final String URL_PROTOCOL_JAR = "jar";
12 
13     /** URL protocol for an entry from a zip file: "zip" */
14     public static final String URL_PROTOCOL_ZIP = "zip";
15 
16     /** URL protocol for an entry from a JBoss jar file: "vfszip" */
17     public static final String URL_PROTOCOL_VFSZIP = "vfszip";
18 
19     /** URL protocol for an entry from a WebSphere jar file: "wsjar" */
20     public static final String URL_PROTOCOL_WSJAR = "wsjar";
21 
22     /** URL protocol for an entry from an OC4J jar file: "code-source" */
23     public static final String URL_PROTOCOL_CODE_SOURCE = "code-source";
24 
25     /** Separator between JAR URL and file path within the JAR */
26     public static final String JAR_URL_SEPARATOR = "!/";

3.resource的继承关系:(http://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/index.html 图 8. Resource 相关的类结构图

图 9. Context 和 Resource 的类关系图
图 9. Context 和 Resource 的类关系图
从上图可以看出,Context 是把资源的加载、解析和描述工作委托给了 ResourcePatternResolver 类来完成,他相当于一个接头人,他把资源的加载、解析和资源的定义整合在一起便于其他组件使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值