|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -206,6 +206,8 @@ import org.springframework.util.StringUtils; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PathMatchingResourcePatternResolver implements ResourcePatternResolver { |
|
|
|
public class PathMatchingResourcePatternResolver implements ResourcePatternResolver { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Resource[] EMPTY_RESOURCE_ARRAY = {}; |
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(PathMatchingResourcePatternResolver.class); |
|
|
|
private static final Log logger = LogFactory.getLog(PathMatchingResourcePatternResolver.class); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -248,6 +250,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
|
|
|
|
|
|
|
|
private PathMatcher pathMatcher = new AntPathMatcher(); |
|
|
|
private PathMatcher pathMatcher = new AntPathMatcher(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean useCaches = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a {@code PathMatchingResourcePatternResolver} with a |
|
|
|
* Create a {@code PathMatchingResourcePatternResolver} with a |
|
|
|
@ -315,6 +319,21 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
return this.pathMatcher; |
|
|
|
return this.pathMatcher; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Specify whether this resolver should use jar caches. Default is {@code true}. |
|
|
|
|
|
|
|
* <p>Switch this flag to {@code false} in order to avoid jar caching at the |
|
|
|
|
|
|
|
* {@link JarURLConnection} level. |
|
|
|
|
|
|
|
* <p>Note that {@link JarURLConnection#setDefaultUseCaches} can be turned off |
|
|
|
|
|
|
|
* independently. This resolver-level setting is designed to only enforce |
|
|
|
|
|
|
|
* {@code JarURLConnection#setUseCaches(false)} if necessary but otherwise |
|
|
|
|
|
|
|
* leaves the JVM-level default in place. |
|
|
|
|
|
|
|
* @since 6.1.19 |
|
|
|
|
|
|
|
* @see JarURLConnection#setUseCaches |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setUseCaches(boolean useCaches) { |
|
|
|
|
|
|
|
this.useCaches = useCaches; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Resource getResource(String location) { |
|
|
|
public Resource getResource(String location) { |
|
|
|
@ -338,7 +357,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
// all class path resources with the given name
|
|
|
|
// all class path resources with the given name
|
|
|
|
Collections.addAll(resources, findAllClassPathResources(locationPatternWithoutPrefix)); |
|
|
|
Collections.addAll(resources, findAllClassPathResources(locationPatternWithoutPrefix)); |
|
|
|
} |
|
|
|
} |
|
|
|
return resources.toArray(new Resource[0]); |
|
|
|
return resources.toArray(EMPTY_RESOURCE_ARRAY); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
// Generally only look for a pattern after a prefix here,
|
|
|
|
// Generally only look for a pattern after a prefix here,
|
|
|
|
@ -371,7 +390,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace("Resolved class path location [" + path + "] to resources " + result); |
|
|
|
logger.trace("Resolved class path location [" + path + "] to resources " + result); |
|
|
|
} |
|
|
|
} |
|
|
|
return result.toArray(new Resource[0]); |
|
|
|
return result.toArray(EMPTY_RESOURCE_ARRAY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -607,7 +626,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace("Resolved location pattern [" + locationPattern + "] to resources " + result); |
|
|
|
logger.trace("Resolved location pattern [" + locationPattern + "] to resources " + result); |
|
|
|
} |
|
|
|
} |
|
|
|
return result.toArray(new Resource[0]); |
|
|
|
return result.toArray(EMPTY_RESOURCE_ARRAY); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -695,6 +714,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol |
|
|
|
|
|
|
|
|
|
|
|
if (con instanceof JarURLConnection jarCon) { |
|
|
|
if (con instanceof JarURLConnection jarCon) { |
|
|
|
// Should usually be the case for traditional JAR files.
|
|
|
|
// Should usually be the case for traditional JAR files.
|
|
|
|
|
|
|
|
if (!this.useCaches) { |
|
|
|
|
|
|
|
jarCon.setUseCaches(false); |
|
|
|
|
|
|
|
} |
|
|
|
jarFile = jarCon.getJarFile(); |
|
|
|
jarFile = jarCon.getJarFile(); |
|
|
|
jarFileUrl = jarCon.getJarFileURL().toExternalForm(); |
|
|
|
jarFileUrl = jarCon.getJarFileURL().toExternalForm(); |
|
|
|
JarEntry jarEntry = jarCon.getJarEntry(); |
|
|
|
JarEntry jarEntry = jarCon.getJarEntry(); |
|
|
|
|