# 2.5. ResourcePatternResolver接口

`ResourcePatternResolver`接口是接口`ResourceLoader`的扩展，它定义了将位置模式（例如，Ant 风格的路径模式）解析为`Resource`对象的策略。

```java
public interface ResourcePatternResolver extends ResourceLoader {

    String CLASSPATH_ALL_URL_PREFIX = "classpath*:";

    Resource[] getResources(String locationPattern) throws IOException;
}
```

从上面可以看出，这个接口还为类路径中所有匹配的资源定义了一个特殊的`classpath*:`资源前缀。请注意，在这种情况下，资源位置应该是没有占位符的路径，例如 `classpath*:/config/beans.xml`. JAR 文件或类路径中的不同目录可以包含多个具有相同路径和相同名称的文件。有关使用资源前缀`classpath*:`通配符支持的更多详细信息，请参阅[应用程序上下文构造函数资源路径](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#resources-app-ctx-wildcards-in-resource-paths)中的通配符及其小节。

可以检查传入的`ResourceLoader`（例如，通过 [`ResourceLoaderAware`](https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#resources-resourceloaderaware)语义提供的）是否也实现了此扩展接口。

`PathMatchingResourcePatternResolver` 是一个独立的实现，可以在`ApplicationContext`外部使用，并且也可以被 `ResourceArrayPropertyEditor` 用于填充 `Resource[]` bean 属性。 `PathMatchingResourcePatternResolver`能够将指定的资源位置路径解析为一个或多个匹配的`Resource`对象。源路径可以是一个简单的路径，它与目标资源有一对一的映射，或者可以包含特殊的 `classpath*:` 前缀和/或内部 Ant 风格的正则表达式（使用 Spring 的 org.springframework.util 进行匹配） .AntPathMatcher 实用程序）。后者实际上都是通配符。

任何标准 `ApplicationContext` 中的默认 `ResourceLoader` 实际上都是 `PathMatchingResourcePatternResolver` 的实例，它实现了 `ResourcePatternResolver` 接口。 `ApplicationContext` 实例本身也是如此，它也实现了 `ResourcePatternResolver` 接口并委托给默认的 `PathMatchingResourcePatternResolver`。
