26
26
import java .lang .reflect .Method ;
27
27
import java .net .JarURLConnection ;
28
28
import java .net .MalformedURLException ;
29
+ import java .net .URI ;
29
30
import java .net .URISyntaxException ;
30
31
import java .net .URL ;
31
32
import java .net .URLClassLoader ;
@@ -765,9 +766,9 @@ protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource
765
766
files .forEach (file -> {
766
767
if (getPathMatcher ().match (patternPath .toString (), file .toString ())) {
767
768
try {
768
- result .add (new UrlResource (file .toUri ()));
769
+ result .add (convertToResource (file .toUri ()));
769
770
}
770
- catch (MalformedURLException ex ) {
771
+ catch (Exception ex ) {
771
772
// ignore
772
773
}
773
774
}
@@ -849,14 +850,12 @@ protected Set<Resource> findAllModulePathResources(String locationPattern) throw
849
850
}
850
851
851
852
@ Nullable
852
- private static Resource findResource (ModuleReader moduleReader , String name ) {
853
+ private Resource findResource (ModuleReader moduleReader , String name ) {
853
854
try {
854
855
return moduleReader .find (name )
855
856
// If it's a "file:" URI, use FileSystemResource to avoid duplicates
856
857
// for the same path discovered via class-path scanning.
857
- .map (uri -> ResourceUtils .URL_PROTOCOL_FILE .equals (uri .getScheme ()) ?
858
- new FileSystemResource (uri .getPath ()) :
859
- UrlResource .from (uri ))
858
+ .map (this ::convertToResource )
860
859
.orElse (null );
861
860
}
862
861
catch (Exception ex ) {
@@ -867,6 +866,12 @@ private static Resource findResource(ModuleReader moduleReader, String name) {
867
866
}
868
867
}
869
868
869
+ private Resource convertToResource (URI uri ) {
870
+ return ResourceUtils .URL_PROTOCOL_FILE .equals (uri .getScheme ()) ?
871
+ new FileSystemResource (uri .getPath ()) :
872
+ UrlResource .from (uri );
873
+ }
874
+
870
875
private static String stripLeadingSlash (String path ) {
871
876
return (path .startsWith ("/" ) ? path .substring (1 ) : path );
872
877
}
0 commit comments