diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 47e14aba1d8..490c5abc5ed 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -892,6 +892,12 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol */ protected Set findAllModulePathResources(String locationPattern) throws IOException { Set result = new LinkedHashSet<>(16); + + // Skip scanning the module path when running in a native image. + if (NativeDetector.inNativeImage()) { + return result; + } + String resourcePattern = stripLeadingSlash(locationPattern); Predicate resourcePatternMatches = (getPathMatcher().isPattern(resourcePattern) ? path -> getPathMatcher().match(resourcePattern, path) :