public class ResourceFinder extends Object
参考Spring的PathMatchingResourcePatternResolver,实现classpath资源查找,利用AntPathMatcher
筛选资源。
Constructor and Description |
---|
ResourceFinder(ClassLoader classLoader)
构造
|
Modifier and Type | Method and Description |
---|---|
protected String |
determineRootDir(String location)
根据给定的路径表达式,找到跟路径
根路径即不包含表达式的路径,如 "/WEB-INF/*.xml" 返回 "/WEB-INF/" |
MultiResource |
find(String locationPattern)
查找给定表达式对应的资源
|
protected MultiResource |
findInDir(FileResource resource,
String subPattern)
遍历目录查找指定表达式匹配的文件列表
|
protected MultiResource |
findInJar(JarResource rootResource,
String subPattern)
查找jar包中的资源
|
static ResourceFinder |
of()
构建新的ResourceFinder,使用当前环境的类加载器
|
static ResourceFinder |
of(ClassLoader classLoader)
构建新的ResourceFinder
|
public ResourceFinder(ClassLoader classLoader)
classLoader
- 类加载器,用于定义查找资源的范围public static ResourceFinder of()
public static ResourceFinder of(ClassLoader classLoader)
classLoader
- 类加载器,用于限定查找范围public MultiResource find(String locationPattern)
locationPattern
- 路径表达式MultiResource
protected MultiResource findInJar(JarResource rootResource, String subPattern) throws IOException
rootResource
- 根资源,为jar包文件subPattern
- 子表达式,如 *.xmlIOException
- IO异常protected MultiResource findInDir(FileResource resource, String subPattern)
resource
- 文件资源subPattern
- 子表达式Copyright © 2025. All rights reserved.