From 56c955158d76461e3c1434c4a3dc6c7cdde04191 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 24 Feb 2025 10:51:30 +0000 Subject: [PATCH] Use Framework's default class loader as default in ImportCandidates Closes gh-44401 --- .../boot/context/annotation/ImportCandidates.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java index 59fe569e94f..24450a9aaab 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * 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. @@ -29,6 +29,7 @@ import java.util.List; import org.springframework.core.io.UrlResource; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; /** * Contains {@code @Configuration} import candidates, usually auto-configurations. @@ -74,7 +75,8 @@ public final class ImportCandidates implements Iterable { * Every line contains the full qualified name of the candidate class. Comments are * supported using the # character. * @param annotation annotation to load - * @param classLoader class loader to use for loading + * @param classLoader class loader to use for loading, or {@code null} to use the + * {@link ClassUtils#getDefaultClassLoader() default class loader} * @return list of names of annotated classes */ public static ImportCandidates load(Class annotation, ClassLoader classLoader) { @@ -92,7 +94,7 @@ public final class ImportCandidates implements Iterable { private static ClassLoader decideClassloader(ClassLoader classLoader) { if (classLoader == null) { - return ImportCandidates.class.getClassLoader(); + return ClassUtils.getDefaultClassLoader(); } return classLoader; }