The ResourcePatternResolver
interface is an extension of the ResourceLoader
interface that
defines a strategy for resolving a location pattern (such as an Ant-style path pattern) into Resource
objects.
public interface ResourcePatternResolver extends ResourceLoader {
String CLASSPATH_ALL_URL_PREFIX = "classpath*:";
Resource[] getResources(String locationPattern) throws IOException;
}
As you can see above, this interface also defines a special resource prefix classpath*:
for all matching
resources in the classpath. Please note that in this case the resource location must be a path without placeholders
- for example, classpath*:/config/beans.xml
. JAR files or different directories in the classpath may
contain multiple files with the same path and the same name.
The passed ResourceLoader
(for example, provided via ResourceLoaderAware
semantics) can be
checked to see if it implements this extended interface.
PathMatchingResourcePatternResolver
is a standalone implementation that can be used outside of ApplicationContext
and is also used by ResourceArrayPropertyEditor
to populate properties of Resource[]
beans. PathMatchingResourcePatternResolver
can resolve a specified resource location path into one or
more corresponding Resource
objects. The source path can be a simple path that has a one-to-one
mapping to the target Resource
, or may contain a special prefix classpath*
:, and/or
internal Ant-style standard expressions (mapped using the org.springframework.util.AntPathMatcher
in
Spring). Both of the latter options are actually wildcards.
The ResourceLoader
by default in any standard ApplicationContext
is actually an
instance of a PathMatchingResourcePatternResolver
that implements the
ResourcePatternResolver
interface. The same is true for the ApplicationContext
instance itself, which also implements the ResourcePatternResolver
interface and delegates it to
the standard PathMatchingResourcePatternResolver
.