ClassPathResource uses specific constructors in createRelative

Issue: SPR-16146
This commit is contained in:
Juergen Hoeller
2017-11-02 16:05:57 +01:00
parent b921d564d2
commit d00e4f17ec
2 changed files with 69 additions and 53 deletions

View File

@@ -105,7 +105,10 @@ public class ClassPathResource extends AbstractFileResolvingResource {
* @param path relative or absolute path within the classpath
* @param classLoader the class loader to load the resource with, if any
* @param clazz the class to load resources with, if any
* @deprecated as of 4.3.13, in favor of selective use of
* {@link #ClassPathResource(String, ClassLoader)} vs {@link #ClassPathResource(String, Class)}
*/
@Deprecated
protected ClassPathResource(String path, @Nullable ClassLoader classLoader, @Nullable Class<?> clazz) {
this.path = StringUtils.cleanPath(path);
this.classLoader = classLoader;
@@ -202,7 +205,8 @@ public class ClassPathResource extends AbstractFileResolvingResource {
@Override
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ClassPathResource(pathToUse, this.classLoader, this.clazz);
return (this.clazz != null ? new ClassPathResource(pathToUse, this.clazz) :
new ClassPathResource(pathToUse, this.classLoader));
}
/**