Locations can either be suitable for ResourceLoader.getResource
(URLs like "file:C:/context.xml", pseudo-URLs like "classpath:/context.xml",
relative file paths like "/WEB-INF/context.xml"), or Ant-style patterns
like "/WEB-INF/*-context.xml".
In the pattern case, the location has to be resolvable to java.io.File
or to a "jar:" URL (leading to a java.net.JarURLConnection)
to allow for searching though the specified directory tree. In particular,
this is not guaranteed to work with a WAR file that is not expanded.
There is special support for retrieving multiple class path resources with the same name, via the "classpath*" prefix. For example, "classpath*:META-INF/beans.xml" will find all "beans.xml" files in the class path, be it in "classes" directories or in JAR files. This is particularly useful for autodetecting config files of the same name at the same location within each jar file.
The "classpath*:" prefix can also be combined with a PathMatcher pattern, for example "classpath*:META-INF/*-beans.xml". In this case, all matching resources in the class path will be found, even if multiple resources of the same name exist in different jar files.
WARNING: Note that "classpath*:" will only work reliably with at least
one root directory before the pattern starts, unless the actual target files
reside in the file system. This means that a pattern like "classpath*:*.xml"
will not retrieve files from the root of jar files but rather only from
the root of expanded directories. This originates from a limitation in the JDK's
ClassLoader.getResources method which only returns file system
locations for a passed-in empty String (indicating potential roots to search).
Warning: Ant-style patterns with "classpath:" resources are not guaranteed to find matching resources if the root package to search is available in multiple class path locations. Preferably, use "classpath*:" with the same Ant-style pattern in such a case, which will search all class path locations that contain the root package.
If neither given a PathMatcher pattern nor a "classpath*:" location, this resolver will return a single resource via the underlying ResourceLoader.
| Field Summary | |
|---|---|
| protected Log |
No description provided. |
| Constructor Summary |
|---|
|
Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader. |
|
Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader. |
|
Create a new PathMatchingResourcePatternResolver. |
|
Create a new PathMatchingResourcePatternResolver. |
| Method Summary | |
|---|---|
| protected String |
Determine the root directory for the given location. |
| protected Set |
Find all resources in the file system that match the given location pattern via the Ant-style PathMatcher. |
| protected Set |
Find all resources in jar files that match the given location pattern via the Ant-style PathMatcher. |
| protected void |
Recursively retrieve files that match the given pattern, adding them to the given result list. |
| protected Resource[] |
Find all class location resources with the given location via the ClassLoader. |
| protected Resource[] |
Find all resources that match the given location pattern via the Ant-style PathMatcher. |
| ClassLoader |
Return the ClassLoader that this pattern resolver works with (never null).
|
| PathMatcher |
Return the PathMatcher that this resource pattern resolver uses. |
| Resource |
No description provided. |
| ResourceLoader |
Return the ResourceLoader that this pattern resolver works with. |
| Resource[] |
No description provided. |
| protected boolean |
Return whether the given resource handle indicates a jar resource that the doFindPathMatchingJarResources method can handle.
|
| protected Set |
Retrieve files that match the given path pattern, checking the given directory and its subdirectories. |
| void |
Set the PathMatcher implementation to use for this resource pattern resolver. |
| Methods inherited from java.langObject |
|---|
public PathMatchingResourcePatternResolver
(
)
ClassLoader access will happen via the thread context class loader.
ClassLoader access will happen via the thread context class loader.
public PathMatchingResourcePatternResolver
(
ResourceLoader
resourceLoader,
ClassLoader
classLoader
)
Used for determining the starting point for file matching,
resolving the root directory location to a java.io.File and
passing it into retrieveMatchingFiles, with the
remainder of the location as pattern.
Will return "/WEB-INF" for the pattern "/WEB-INF/*.xml", for example.
protected
Set
doFindPathMatchingFileResources
(
Resource
rootDirResource,
String
subPattern
)
null). doFindPathMatchingJarResources method can handle.
The default implementation checks against the URL protocols "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server and IBM WebSphere, respectively, but can be treated like jar files).