Use beanClassLoader when checking excluded auto-configuration classes

When validating exclusions, prefer the selector's beanClassLoader for
ClassUtils.isPresent checks and fall back to the selector class loader
if the beanClassLoader is not set.

This makes presence checks consistent with the classloader context used
for loading auto-configuration candidates.

See gh-48129

Signed-off-by: linw-bai <107357009+linw-bai@users.noreply.github.com>
This commit is contained in:
linw-bai
2025-11-14 09:47:45 +01:00
committed by Stéphane Nicoll
parent 2f1f964a2a
commit 8bcab02efd
@@ -205,8 +205,9 @@ public class AutoConfigurationImportSelector implements DeferredImportSelector,
private void checkExcludedClasses(List<String> configurations, Set<String> exclusions) {
List<String> invalidExcludes = new ArrayList<>(exclusions.size());
ClassLoader classLoader = (this.beanClassLoader != null) ? this.beanClassLoader : getClass().getClassLoader();
for (String exclusion : exclusions) {
if (ClassUtils.isPresent(exclusion, getClass().getClassLoader()) && !configurations.contains(exclusion)) {
if (ClassUtils.isPresent(exclusion, classLoader) && !configurations.contains(exclusion)) {
invalidExcludes.add(exclusion);
}
}