spring resource
生活随笔
收集整理的這篇文章主要介紹了
spring resource
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 的類關系圖
從上圖可以看出,Context 是把資源的加載、解析和描述工作委托給了 ResourcePatternResolver 類來完成,他相當于一個接頭人,他把資源的加載、解析和資源的定義整合在一起便于其他組件使用。
轉載于:https://www.cnblogs.com/davidwang456/archive/2013/03/21/2972916.html
總結
以上是生活随笔為你收集整理的spring resource的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring 资源访问剖析和策略模式应用
- 下一篇: spring AOP策略模式使用