17
17
18
18
import java .lang .annotation .Annotation ;
19
19
import java .util .Arrays ;
20
- import java .util .Collection ;
21
20
import java .util .HashSet ;
22
21
import java .util .Set ;
23
- import java .util .function .Consumer ;
24
- import java .util .stream .Collectors ;
25
22
26
23
import org .springframework .beans .factory .annotation .AnnotatedBeanDefinition ;
27
24
import org .springframework .beans .factory .config .BeanDefinition ;
31
28
import org .springframework .core .env .Environment ;
32
29
import org .springframework .core .io .ResourceLoader ;
33
30
import org .springframework .core .type .filter .AnnotationTypeFilter ;
34
- import org .springframework .core .type .filter .TypeFilter ;
35
31
import org .springframework .lang .Nullable ;
36
32
import org .springframework .util .ClassUtils ;
37
33
@@ -50,10 +46,6 @@ public class AnnotatedTypeScanner implements ResourceLoaderAware, EnvironmentAwa
50
46
private @ Nullable ResourceLoader resourceLoader ;
51
47
private @ Nullable Environment environment ;
52
48
53
- private Consumer <ClassNotFoundException > classNotFoundAction = ex -> {
54
- throw new IllegalStateException (ex );
55
- };
56
-
57
49
/**
58
50
* Creates a new {@link AnnotatedTypeScanner} for the given annotation types.
59
51
*
@@ -72,18 +64,9 @@ public AnnotatedTypeScanner(Class<? extends Annotation>... annotationTypes) {
72
64
*/
73
65
@ SafeVarargs
74
66
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 ) {
84
67
68
+ this .annotationTypess = Arrays .asList (annotationTypes );
85
69
this .considerInterfaces = considerInterfaces ;
86
- this .annotationTypess = annotationTypes ;
87
70
}
88
71
89
72
@ Override
@@ -96,15 +79,11 @@ public void setEnvironment(Environment environment) {
96
79
this .environment = environment ;
97
80
}
98
81
99
- void setClassNotFoundAction (Consumer <ClassNotFoundException > classNotFoundAction ) {
100
- this .classNotFoundAction = classNotFoundAction ;
101
- }
102
-
103
82
public Set <Class <?>> findTypes (String ... basePackages ) {
104
83
return findTypes (Arrays .asList (basePackages ));
105
84
}
106
85
107
- Set <Class <?>> findTypes (Iterable <String > basePackages , Collection < TypeFilter > filters ) {
86
+ public Set <Class <?>> findTypes (Iterable <String > basePackages ) {
108
87
109
88
ClassPathScanningCandidateComponentProvider provider = new InterfaceAwareScanner (considerInterfaces );
110
89
@@ -116,7 +95,9 @@ Set<Class<?>> findTypes(Iterable<String> basePackages, Collection<TypeFilter> fi
116
95
provider .setEnvironment (environment );
117
96
}
118
97
119
- filters .forEach (provider ::addIncludeFilter );
98
+ for (Class <? extends Annotation > annotationType : annotationTypess ) {
99
+ provider .addIncludeFilter (new AnnotationTypeFilter (annotationType , true , considerInterfaces ));
100
+ }
120
101
121
102
Set <Class <?>> types = new HashSet <>();
122
103
@@ -137,18 +118,14 @@ Set<Class<?>> findTypes(Iterable<String> basePackages, Collection<TypeFilter> fi
137
118
try {
138
119
types .add (ClassUtils .forName (beanClassName , classLoader ));
139
120
} catch (ClassNotFoundException o_O ) {
140
- classNotFoundAction . accept (o_O );
121
+ throw new IllegalStateException (o_O );
141
122
}
142
123
}
143
124
}
144
125
145
126
return types ;
146
127
}
147
128
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
-
152
129
/**
153
130
* Custom extension of {@link ClassPathScanningCandidateComponentProvider} to make sure interfaces to not get dropped
154
131
* from scanning results.
0 commit comments