Tag: www source string application oca XML bulk location file
Spring's Resource
The resource interface is used internally by the spring framework as an abstraction and interface for all resources. For example:
Beanfactory beanfactory = new Xmlbeanfactory (New Classpathresource ("..."));
Classpathresource is a specific type of implementation of resource that represents a resource that is actually located in Classpath.
Resource interface can be based on the different types of resources, or resources in different situations, give the corresponding specific implementation:
A. Bytearrayresource the data provided by an array of byte (byte) as a resource
B. Classpathresource the implementation loads specific resources and encapsulates them from the Java application's Classpath
C. Filesystemresource to the Java.io.File type of encapsulation, so we can be a file or URL in the form of the type of resources to access, as long as can be dealt with file, basically with Filesystemresource can also.
D. Urlresource the implementation class for locating a specific resource through Java.net.URL
If the above resources do not meet the requirements, can be based on the corresponding scenario to give their own implementation, just implement the resource interface is.
Resourceloader
Resourceloader's job is to find and locate resources. The specific resource lookup location strategy is given by the corresponding Resourceloader implementation class. Resourceloder is defined as follows:
Public interface Resourceloader { String classpath_url_prefix = resourceutils.classpath_url_prefix; Resource getresource (String location); ClassLoader getClassLoader ();}
Resourceloader----Resourcepatternresolver for bulk lookups
Resourcepatternresolver can return multiple resource instances each time according to the specified resource path matching pattern
Defined as follows:
Public interface Resourcepatternresolver extends resourceloader { String classpath_all_url_prefix = "CLASSPATH *:"; Resource[] Getresources (String locationpattern) throws IOException;}
Hierarchy of Resourcehe and Resourceloader (excerpt from http://www.jianshu.com/p/9cdd6d750216):
ApplicationContext and Resourceloader
Look again at the beanfactory and ApplicationContext inheritance diagram:
ApplicationContext inherited the Resourcepatternresolver, of course, the indirect implementation of the Resourceloader interface. So, the ApplicationContext implementation can be seen as a resourceloader or even a resourcepatternresolver. This is the truth of ApplicationContext support for the unified resource loading strategy within spring.
In general, all ApplicationContext implementation classes inherit abstractapplicationcontext directly or indirectly, from which you can see all the relationships between ApplicationContext and Resourceloader
So abstractapplication can be used as Resourceloader and Resourcepatternresolver.
"Spring Revelation" (10)----ApplicationContext Unified Resource Loading strategy