Skip to content

Commit be84bca

Browse files
Reset annotatedTypeScanner
1 parent 352bbd9 commit be84bca

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

src/main/java/org/springframework/data/util/AnnotatedTypeScanner.java

+6-29
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
import java.lang.annotation.Annotation;
1919
import java.util.Arrays;
20-
import java.util.Collection;
2120
import java.util.HashSet;
2221
import java.util.Set;
23-
import java.util.function.Consumer;
24-
import java.util.stream.Collectors;
2522

2623
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2724
import org.springframework.beans.factory.config.BeanDefinition;
@@ -31,7 +28,6 @@
3128
import org.springframework.core.env.Environment;
3229
import org.springframework.core.io.ResourceLoader;
3330
import org.springframework.core.type.filter.AnnotationTypeFilter;
34-
import org.springframework.core.type.filter.TypeFilter;
3531
import org.springframework.lang.Nullable;
3632
import org.springframework.util.ClassUtils;
3733

@@ -50,10 +46,6 @@ public class AnnotatedTypeScanner implements ResourceLoaderAware, EnvironmentAwa
5046
private @Nullable ResourceLoader resourceLoader;
5147
private @Nullable Environment environment;
5248

53-
private Consumer<ClassNotFoundException> classNotFoundAction = ex -> {
54-
throw new IllegalStateException(ex);
55-
};
56-
5749
/**
5850
* Creates a new {@link AnnotatedTypeScanner} for the given annotation types.
5951
*
@@ -72,18 +64,9 @@ public AnnotatedTypeScanner(Class<? extends Annotation>... annotationTypes) {
7264
*/
7365
@SafeVarargs
7466
public AnnotatedTypeScanner(boolean considerInterfaces, Class<? extends Annotation>... annotationTypes) {
75-
this(considerInterfaces, Arrays.asList(annotationTypes));
76-
}
77-
78-
/**
79-
* @param considerInterfaces
80-
* @param annotationTypes
81-
* @since 3.0
82-
*/
83-
public AnnotatedTypeScanner(boolean considerInterfaces, Collection<Class<? extends Annotation>> annotationTypes) {
8467

68+
this.annotationTypess = Arrays.asList(annotationTypes);
8569
this.considerInterfaces = considerInterfaces;
86-
this.annotationTypess = annotationTypes;
8770
}
8871

8972
@Override
@@ -96,15 +79,11 @@ public void setEnvironment(Environment environment) {
9679
this.environment = environment;
9780
}
9881

99-
void setClassNotFoundAction(Consumer<ClassNotFoundException> classNotFoundAction) {
100-
this.classNotFoundAction = classNotFoundAction;
101-
}
102-
10382
public Set<Class<?>> findTypes(String... basePackages) {
10483
return findTypes(Arrays.asList(basePackages));
10584
}
10685

107-
Set<Class<?>> findTypes(Iterable<String> basePackages, Collection<TypeFilter> filters) {
86+
public Set<Class<?>> findTypes(Iterable<String> basePackages) {
10887

10988
ClassPathScanningCandidateComponentProvider provider = new InterfaceAwareScanner(considerInterfaces);
11089

@@ -116,7 +95,9 @@ Set<Class<?>> findTypes(Iterable<String> basePackages, Collection<TypeFilter> fi
11695
provider.setEnvironment(environment);
11796
}
11897

119-
filters.forEach(provider::addIncludeFilter);
98+
for (Class<? extends Annotation> annotationType : annotationTypess) {
99+
provider.addIncludeFilter(new AnnotationTypeFilter(annotationType, true, considerInterfaces));
100+
}
120101

121102
Set<Class<?>> types = new HashSet<>();
122103

@@ -137,18 +118,14 @@ Set<Class<?>> findTypes(Iterable<String> basePackages, Collection<TypeFilter> fi
137118
try {
138119
types.add(ClassUtils.forName(beanClassName, classLoader));
139120
} catch (ClassNotFoundException o_O) {
140-
classNotFoundAction.accept(o_O);
121+
throw new IllegalStateException(o_O);
141122
}
142123
}
143124
}
144125

145126
return types;
146127
}
147128

148-
public Set<Class<?>> findTypes(Iterable<String> basePackages) {
149-
return findTypes(basePackages, Streamable.of(annotationTypess).stream().map(annotation -> new AnnotationTypeFilter(annotation, true, considerInterfaces)).collect(Collectors.toSet()));
150-
}
151-
152129
/**
153130
* Custom extension of {@link ClassPathScanningCandidateComponentProvider} to make sure interfaces to not get dropped
154131
* from scanning results.

0 commit comments

Comments
 (0)