diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ApplicationResourceLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ApplicationResourceLoader.java index 40a778ace1d..63b6577272f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ApplicationResourceLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ApplicationResourceLoader.java @@ -131,7 +131,7 @@ public class ApplicationResourceLoader extends DefaultResourceLoader { * class loader at the time this call is made. * @param resourceLoader the delegate resource loader * @param preferFileResolution if file based resolution is preferred when a suitable - * {@link ResourceFilePathResolver} support the resource + * {@link FilePathResolver} support the resource * @return a {@link ResourceLoader} instance * @since 3.4.1 */ @@ -160,8 +160,8 @@ public class ApplicationResourceLoader extends DefaultResourceLoader { Assert.notNull(resourceLoader, "'resourceLoader' must not be null"); Assert.notNull(springFactoriesLoader, "'springFactoriesLoader' must not be null"); List protocolResolvers = springFactoriesLoader.load(ProtocolResolver.class); - List filePathResolvers = (preferFileResolution) - ? springFactoriesLoader.load(ResourceFilePathResolver.class) : Collections.emptyList(); + List filePathResolvers = (preferFileResolution) + ? springFactoriesLoader.load(FilePathResolver.class) : Collections.emptyList(); return new ProtocolResolvingResourceLoader(resourceLoader, protocolResolvers, filePathResolvers); } @@ -188,6 +188,28 @@ public class ApplicationResourceLoader extends DefaultResourceLoader { } + /** + * Strategy interface registered in {@code spring.factories} and used by + * {@link ApplicationResourceLoader} to determine the file path of loaded resource + * when it can also be represented as a {@link FileSystemResource}. + * + * @author Phillip Webb + * @since 3.4.5 + */ + public interface FilePathResolver { + + /** + * Return the {@code path} of the given resource if it can also be represented as + * a {@link FileSystemResource}. + * @param location the location used to create the resource + * @param resource the resource to check + * @return the file path of the resource or {@code null} if the it is not possible + * to represent the resource as a {@link FileSystemResource}. + */ + String resolveFilePath(String location, Resource resource); + + } + /** * An application {@link Resource}. */ @@ -214,10 +236,10 @@ public class ApplicationResourceLoader extends DefaultResourceLoader { private final List protocolResolvers; - private final List filePathResolvers; + private final List filePathResolvers; ProtocolResolvingResourceLoader(ResourceLoader resourceLoader, List protocolResolvers, - List filePathResolvers) { + List filePathResolvers) { this.resourceLoader = resourceLoader; this.protocolResolvers = protocolResolvers; this.filePathResolvers = filePathResolvers; @@ -239,12 +261,12 @@ public class ApplicationResourceLoader extends DefaultResourceLoader { } } Resource resource = this.resourceLoader.getResource(location); - String fileSystemPath = getFileSystemPath(location, resource); - return (fileSystemPath != null) ? new ApplicationResource(fileSystemPath) : resource; + String filePath = getFilePath(location, resource); + return (filePath != null) ? new ApplicationResource(filePath) : resource; } - private String getFileSystemPath(String location, Resource resource) { - for (ResourceFilePathResolver filePathResolver : this.filePathResolvers) { + private String getFilePath(String location, Resource resource) { + for (FilePathResolver filePathResolver : this.filePathResolvers) { String filePath = filePathResolver.resolveFilePath(location, resource); if (filePath != null) { return filePath; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ClassPathResourceFilePathResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ClassPathResourceFilePathResolver.java index aca69aaccb9..a5e89165190 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ClassPathResourceFilePathResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ClassPathResourceFilePathResolver.java @@ -16,16 +16,17 @@ package org.springframework.boot.io; +import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; /** - * {@link ResourceFilePathResolver} for {@link ClassPathResource}. + * {@link FilePathResolver} for {@link ClassPathResource}. * * @author Phillip Webb */ -class ClassPathResourceFilePathResolver implements ResourceFilePathResolver { +class ClassPathResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver { @Override public String resolveFilePath(String location, Resource resource) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ResourceFilePathResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ResourceFilePathResolver.java deleted file mode 100644 index b3c9fe8b6ad..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/io/ResourceFilePathResolver.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2012-2025 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.io; - -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; - -/** - * Strategy interface registered in {@code spring.factories} and used by - * {@link ApplicationResourceLoader} to determine the file path of loaded resource when it - * can also be represented as a {@link FileSystemResource}. - * - * @author Phillip Webb - * @since 3.4.5 - */ -public interface ResourceFilePathResolver { - - /** - * Return the {@code path} of the given resource if it can also be represented as a - * {@link FileSystemResource}. - * @param location the location used to create the resource - * @param resource the resource to check - * @return the file path of the resource or {@code null} if the it is not possible to - * represent the resource as a {@link FileSystemResource}. - */ - String resolveFilePath(String location, Resource resource); - -} diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/ServletContextResourceFilePathResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/ServletContextResourceFilePathResolver.java index 9c0e571d545..4ed4a7ea412 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/ServletContextResourceFilePathResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/context/ServletContextResourceFilePathResolver.java @@ -16,17 +16,18 @@ package org.springframework.boot.web.context; -import org.springframework.boot.io.ResourceFilePathResolver; +import org.springframework.boot.io.ApplicationResourceLoader; +import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver; import org.springframework.core.io.Resource; import org.springframework.util.ClassUtils; import org.springframework.web.context.support.ServletContextResource; /** - * {@link ResourceFilePathResolver} for {@link ServletContextResource}. + * {@link FilePathResolver} for {@link ServletContextResource}. * * @author Phillip Webb */ -class ServletContextResourceFilePathResolver implements ResourceFilePathResolver { +class ServletContextResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver { private static final String RESOURCE_CLASS_NAME = "org.springframework.web.context.support.ServletContextResource"; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/FilteredReactiveWebContextResourceFilePathResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/FilteredReactiveWebContextResourceFilePathResolver.java index 9876bc0aad9..4494cd35623 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/FilteredReactiveWebContextResourceFilePathResolver.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/FilteredReactiveWebContextResourceFilePathResolver.java @@ -16,15 +16,16 @@ package org.springframework.boot.web.reactive.context; -import org.springframework.boot.io.ResourceFilePathResolver; +import org.springframework.boot.io.ApplicationResourceLoader; +import org.springframework.boot.io.ApplicationResourceLoader.FilePathResolver; import org.springframework.core.io.Resource; /** - * {@link ResourceFilePathResolver} for {@link FilteredReactiveWebContextResource}. + * {@link FilePathResolver} for {@link FilteredReactiveWebContextResource}. * * @author Dmytro Nosan */ -class FilteredReactiveWebContextResourceFilePathResolver implements ResourceFilePathResolver { +class FilteredReactiveWebContextResourceFilePathResolver implements ApplicationResourceLoader.FilePathResolver { @Override public String resolveFilePath(String location, Resource resource) { diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories index 6d99bfabd27..44b0c8c1bbf 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories @@ -107,7 +107,7 @@ org.springframework.core.io.ProtocolResolver=\ org.springframework.boot.io.Base64ProtocolResolver # Resource File Path Resolvers -org.springframework.boot.io.ResourceFilePathResolver=\ +org.springframework.boot.io.ApplicationResourceLoader$FilePathResolver=\ org.springframework.boot.io.ClassPathResourceFilePathResolver,\ org.springframework.boot.web.context.ServletContextResourceFilePathResolver,\ org.springframework.boot.web.reactive.context.FilteredReactiveWebContextResourceFilePathResolver