Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
08748eca
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
08748eca
编写于
12月 18, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PathMatchingResourcePatternResolver evaluates classpath manifest entries as well
Issue: SPR-13685
上级
2cfe00ce
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
3 deletion
+51
-3
spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
.../core/io/support/PathMatchingResourcePatternResolver.java
+51
-3
未找到文件。
spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
浏览文件 @
08748eca
...
...
@@ -144,6 +144,9 @@ import org.springframework.util.StringUtils;
* root of expanded directories. This originates from a limitation in the JDK's
* {@code ClassLoader.getResources()} method which only returns file system
* locations for a passed-in empty String (indicating potential roots to search).
* This {@code ResourcePatternResolver} implementation is trying to mitigate the
* jar root lookup limitation through {@link URLClassLoader} introspection and
* "java.class.path" manifest evaluation; however, without portability guarantees.
*
* <p><b>WARNING:</b> Ant-style patterns with "classpath:" resources are not
* guaranteed to find matching resources if the root package to search is available
...
...
@@ -156,9 +159,9 @@ import org.springframework.util.StringUtils;
* classpath:com/mycompany/**/service-context.xml
* </pre>
* is used to try to resolve it, the resolver will work off the (first) URL
* returned by {@code getResource("com/mycompany");}. If this base package
*
node exists in multiple classloader locations, the actual end resource may
*
not be
underneath. Therefore, preferably, use "{@code classpath*:}" with the same
* returned by {@code getResource("com/mycompany");}. If this base package
node
*
exists in multiple classloader locations, the actual end resource may not be
* underneath. Therefore, preferably, use "{@code classpath*:}" with the same
* Ant-style pattern in such a case, which will search <i>all</i> class path
* locations that contain the root package.
*
...
...
@@ -166,6 +169,7 @@ import org.springframework.util.StringUtils;
* @author Colin Sampaleanu
* @author Marius Bogoevici
* @author Costin Leau
* @author Phil Webb
* @since 1.0.2
* @see #CLASSPATH_ALL_URL_PREFIX
* @see org.springframework.util.AntPathMatcher
...
...
@@ -316,6 +320,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
* Called by {@link #findAllClassPathResources(String)}.
* @param path the absolute path within the classpath (never a leading slash)
* @return a mutable Set of matching Resource instances
* @since 4.1.1
*/
protected
Set
<
Resource
>
doFindAllClassPathResources
(
String
path
)
throws
IOException
{
Set
<
Resource
>
result
=
new
LinkedHashSet
<
Resource
>(
16
);
...
...
@@ -350,6 +355,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
* given set of resources in the form of pointers to the root of the jar file content.
* @param classLoader the ClassLoader to search (including its ancestors)
* @param result the set of resources to add jar roots to
* @since 4.1.1
*/
protected
void
addAllClassLoaderJarRoots
(
ClassLoader
classLoader
,
Set
<
Resource
>
result
)
{
if
(
classLoader
instanceof
URLClassLoader
)
{
...
...
@@ -379,8 +385,15 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
}
}
if
(
classLoader
==
ClassLoader
.
getSystemClassLoader
())
{
// "java.class.path" manifest evaluation...
addClassPathManifestEntries
(
result
);
}
if
(
classLoader
!=
null
)
{
try
{
// Hierarchy traversal...
addAllClassLoaderJarRoots
(
classLoader
.
getParent
(),
result
);
}
catch
(
Exception
ex
)
{
...
...
@@ -392,6 +405,41 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
}
/**
* Determine jar file references from the "java.class.path." manifest property and add them
* to the given set of resources in the form of pointers to the root of the jar file content.
* @param result the set of resources to add jar roots to
* @since 4.3
*/
protected
void
addClassPathManifestEntries
(
Set
<
Resource
>
result
)
{
try
{
String
javaClassPathProperty
=
System
.
getProperty
(
"java.class.path"
);
for
(
String
url
:
StringUtils
.
delimitedListToStringArray
(
javaClassPathProperty
,
System
.
getProperty
(
"path.separator"
)))
{
try
{
if
(
url
.
endsWith
(
ResourceUtils
.
JAR_FILE_EXTENSION
))
{
UrlResource
jarResource
=
new
UrlResource
(
ResourceUtils
.
JAR_URL_PREFIX
+
ResourceUtils
.
FILE_URL_PREFIX
+
url
+
ResourceUtils
.
JAR_URL_SEPARATOR
);
if
(
jarResource
.
exists
())
{
result
.
add
(
jarResource
);
}
}
}
catch
(
MalformedURLException
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Cannot search for matching files underneath ["
+
url
+
"] because it cannot be converted to a valid 'jar:' URL: "
+
ex
.
getMessage
());
}
}
}
}
catch
(
Exception
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Failed to evaluate 'java.class.path' manifest entries: "
+
ex
);
}
}
}
/**
* Find all resources that match the given location pattern via the
* Ant-style PathMatcher. Supports resources in jar files and zip files
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录