1. ResourcePatternResolver
ResourcePatternResolver定义了getResources来查找资源
PathMatchingResourcePatternResolver提供了以classpath开头的通配符方式查询,否则会调用ResourceLoader的getResource方法来查找
public interface ResourcePatternResolver extends ResourceLoader {
Resource[] getResources(String locationPattern) throws IOException;
}
2.加载本地Class
@Test
public void singleResourceOnFileSystem() throws IOException {
Resource[] resources =
resolver.getResources("org/springframework/core/io/support
/PathMatchingResourcePatternResolverTests.class");
}
内部还是以ResourceLoader来加载
3. 加载jar包的资源
@Test
public void singleResourceInJar() throws IOException {
Resource[] resources = resolver.getResources("java/lang/URL.class");
assertEquals(1, resources.length);
assertProtocolAndFilenames(resources, "jar", "URL.class");
}
4.以classpath*通配符的方式加载本地class
@Test
public void classpathStarWithPatternOnFileSystem() throws IOException {
Resource[] resources = resolver.getResources("classpath*:org/springframework/core/io/sup*/*.class");
}
5.以classpath*通配符的方式加载jar包class
@Test
public void classpathStartWithPatternInJar() throws IOException {
Resource[] resources = resolver.getResources("classpath*:org/apache/commons/logging/*.class");
resources = resolver.getResources("classpath*:com/alibaba/dubbo/rpc/filter/**/*.class");
}