Commit d92441e5 authored by Johnny Lim's avatar Johnny Lim Committed by Stephane Nicoll

Update assertion message in AnnotatedClassFinder.scanPackage()

Closes gh-13989
parent b9fcb6a5
...@@ -41,6 +41,8 @@ public final class AnnotatedClassFinder { ...@@ -41,6 +41,8 @@ public final class AnnotatedClassFinder {
private static final Map<String, Class<?>> cache = Collections private static final Map<String, Class<?>> cache = Collections
.synchronizedMap(new Cache(40)); .synchronizedMap(new Cache(40));
private final Class<? extends Annotation> annotationType;
private final ClassPathScanningCandidateComponentProvider scanner; private final ClassPathScanningCandidateComponentProvider scanner;
/** /**
...@@ -49,6 +51,7 @@ public final class AnnotatedClassFinder { ...@@ -49,6 +51,7 @@ public final class AnnotatedClassFinder {
*/ */
public AnnotatedClassFinder(Class<? extends Annotation> annotationType) { public AnnotatedClassFinder(Class<? extends Annotation> annotationType) {
Assert.notNull(annotationType, "AnnotationType must not be null"); Assert.notNull(annotationType, "AnnotationType must not be null");
this.annotationType = annotationType;
this.scanner = new ClassPathScanningCandidateComponentProvider(false); this.scanner = new ClassPathScanningCandidateComponentProvider(false);
this.scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType)); this.scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType));
this.scanner.setResourcePattern("*.class"); this.scanner.setResourcePattern("*.class");
...@@ -88,8 +91,8 @@ public final class AnnotatedClassFinder { ...@@ -88,8 +91,8 @@ public final class AnnotatedClassFinder {
Set<BeanDefinition> components = this.scanner.findCandidateComponents(source); Set<BeanDefinition> components = this.scanner.findCandidateComponents(source);
if (!components.isEmpty()) { if (!components.isEmpty()) {
Assert.state(components.size() == 1, Assert.state(components.size() == 1,
() -> "Found multiple @SpringBootConfiguration annotated classes " () -> "Found multiple @" + this.annotationType.getSimpleName()
+ components); + " annotated classes " + components);
return ClassUtils.resolveClassName( return ClassUtils.resolveClassName(
components.iterator().next().getBeanClassName(), null); components.iterator().next().getBeanClassName(), null);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment