Browse Source

Revert "Use Framework's default class loader as default in ImportCandidates"

This reverts commit 56c955158d.

See gh-44401
pull/44467/head
Andy Wilkinson 1 year ago
parent
commit
21a5319362
  1. 8
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java
  2. 3
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ImportCandidatesTests.java

8
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2025 the original author or authors.
* Copyright 2012-2022 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,7 +29,6 @@ import java.util.List; @@ -29,7 +29,6 @@ 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.
@ -75,8 +74,7 @@ public final class ImportCandidates implements Iterable<String> { @@ -75,8 +74,7 @@ public final class ImportCandidates implements Iterable<String> {
* 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, or {@code null} to use the
* {@link ClassUtils#getDefaultClassLoader() default class loader}
* @param classLoader class loader to use for loading
* @return list of names of annotated classes
*/
public static ImportCandidates load(Class<?> annotation, ClassLoader classLoader) {
@ -94,7 +92,7 @@ public final class ImportCandidates implements Iterable<String> { @@ -94,7 +92,7 @@ public final class ImportCandidates implements Iterable<String> {
private static ClassLoader decideClassloader(ClassLoader classLoader) {
if (classLoader == null) {
return ClassUtils.getDefaultClassLoader();
return ImportCandidates.class.getClassLoader();
}
return classLoader;
}

3
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/annotation/ImportCandidatesTests.java

@ -47,7 +47,8 @@ class ImportCandidatesTests { @@ -47,7 +47,8 @@ class ImportCandidatesTests {
""")
void loadReadsFromClasspathFile() {
ImportCandidates candidates = ImportCandidates.load(TestAnnotation.class, null);
ImportCandidates candidates = ImportCandidates.load(TestAnnotation.class,
Thread.currentThread().getContextClassLoader());
assertThat(candidates).containsExactly("class1", "class2", "class3");
}

Loading…
Cancel
Save