|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import org.springframework.aot.hint.ResourceHints;
|
24 | 24 | import org.springframework.lang.Nullable;
|
25 | 25 | import org.springframework.util.Assert;
|
| 26 | +import org.springframework.util.ClassUtils; |
26 | 27 | import org.springframework.util.ResourceUtils;
|
27 | 28 |
|
28 | 29 | /**
|
@@ -66,19 +67,21 @@ public FilePatternResourceHintsRegistrar(List<String> filePrefixes, List<String>
|
66 | 67 |
|
67 | 68 | @Deprecated(since = "6.0.12", forRemoval = true)
|
68 | 69 | public void registerHints(ResourceHints hints, @Nullable ClassLoader classLoader) {
|
69 |
| - ClassLoader classLoaderToUse = (classLoader != null ? classLoader : getClass().getClassLoader()); |
70 |
| - List<String> includes = new ArrayList<>(); |
71 |
| - for (String location : this.classpathLocations) { |
72 |
| - if (classLoaderToUse.getResource(location) != null) { |
73 |
| - for (String filePrefix : this.filePrefixes) { |
74 |
| - for (String fileExtension : this.fileExtensions) { |
75 |
| - includes.add(location + filePrefix + "*" + fileExtension); |
| 70 | + ClassLoader classLoaderToUse = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader()); |
| 71 | + if (classLoaderToUse != null) { |
| 72 | + List<String> includes = new ArrayList<>(); |
| 73 | + for (String location : this.classpathLocations) { |
| 74 | + if (classLoaderToUse.getResource(location) != null) { |
| 75 | + for (String filePrefix : this.filePrefixes) { |
| 76 | + for (String fileExtension : this.fileExtensions) { |
| 77 | + includes.add(location + filePrefix + "*" + fileExtension); |
| 78 | + } |
76 | 79 | }
|
77 | 80 | }
|
78 | 81 | }
|
79 |
| - } |
80 |
| - if (!includes.isEmpty()) { |
81 |
| - hints.registerPattern(hint -> hint.includes(includes.toArray(String[]::new))); |
| 82 | + if (!includes.isEmpty()) { |
| 83 | + hints.registerPattern(hint -> hint.includes(includes.toArray(String[]::new))); |
| 84 | + } |
82 | 85 | }
|
83 | 86 | }
|
84 | 87 |
|
@@ -246,8 +249,7 @@ private FilePatternResourceHintsRegistrar build() {
|
246 | 249 | * classpath location that resolves against the {@code ClassLoader}, files
|
247 | 250 | * with the configured file prefixes and extensions are registered.
|
248 | 251 | * @param hints the hints contributed so far for the deployment unit
|
249 |
| - * @param classLoader the classloader, or {@code null} if even the system |
250 |
| - * ClassLoader isn't accessible |
| 252 | + * @param classLoader the ClassLoader to use, or {@code null} for the default |
251 | 253 | */
|
252 | 254 | public void registerHints(ResourceHints hints, @Nullable ClassLoader classLoader) {
|
253 | 255 | build().registerHints(hints, classLoader);
|
|
0 commit comments