Skip to content

Commit df6feb3

Browse files
artsiomsnicoll
authored andcommitted
Make SpringBootConfigurationFinder public and usable with other annotations
See gh-13904
1 parent e60af72 commit df6feb3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootConfigurationFinder.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.test.context;
1818

19+
import java.lang.annotation.Annotation;
1920
import java.util.Collections;
2021
import java.util.LinkedHashMap;
2122
import java.util.Map;
@@ -29,21 +30,34 @@
2930
import org.springframework.util.ClassUtils;
3031

3132
/**
32-
* Internal utility class to scan for a {@link SpringBootConfiguration} class.
33+
* Utility class to scan for a {@link SpringBootConfiguration} or custom annotation.
3334
*
3435
* @author Phillip Webb
36+
* @author Artsiom Yudovin
37+
* @since 2.1.0
3538
*/
36-
final class SpringBootConfigurationFinder {
39+
public final class SpringBootConfigurationFinder {
3740

3841
private static final Map<String, Class<?>> cache = Collections
3942
.synchronizedMap(new Cache(40));
4043

4144
private final ClassPathScanningCandidateComponentProvider scanner;
4245

43-
SpringBootConfigurationFinder() {
46+
/**
47+
* Default constructor initializing finder to scan for a {@link SpringBootConfiguration} annotation.
48+
*/
49+
public SpringBootConfigurationFinder() {
50+
this(SpringBootConfiguration.class);
51+
}
52+
53+
/**
54+
* Customiable constructor allow to provide the custom annotation to scan for.
55+
* @param annotationType Annotation to scan for.
56+
*/
57+
public SpringBootConfigurationFinder(Class<? extends Annotation> annotationType) {
4458
this.scanner = new ClassPathScanningCandidateComponentProvider(false);
4559
this.scanner.addIncludeFilter(
46-
new AnnotationTypeFilter(SpringBootConfiguration.class));
60+
new AnnotationTypeFilter(annotationType));
4761
this.scanner.setResourcePattern("*.class");
4862
}
4963

0 commit comments

Comments
 (0)