16
16
17
17
package org .springframework .context .annotation ;
18
18
19
- import static org .springframework .context .annotation .ConfigurationClassUtils .isConfigurationCandidate ;
20
-
21
19
import java .io .IOException ;
20
+ import java .lang .annotation .Annotation ;
21
+ import java .util .ArrayList ;
22
22
import java .util .Collections ;
23
23
import java .util .Comparator ;
24
24
import java .util .HashMap ;
35
35
import org .springframework .beans .factory .parsing .Problem ;
36
36
import org .springframework .beans .factory .parsing .ProblemReporter ;
37
37
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
38
- import org .springframework .core .annotation .AnnotationUtils ;
39
38
import org .springframework .core .env .Environment ;
40
39
import org .springframework .core .env .PropertySource ;
41
40
import org .springframework .core .io .ResourceLoader ;
42
- import org .springframework .core .io .ResourcePropertySource ;
41
+ import org .springframework .core .io .support . ResourcePropertySource ;
43
42
import org .springframework .core .type .AnnotationMetadata ;
44
43
import org .springframework .core .type .MethodMetadata ;
45
44
import org .springframework .core .type .StandardAnnotationMetadata ;
@@ -167,7 +166,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
167
166
for (String memberClassName : metadata .getMemberClassNames ()) {
168
167
MetadataReader reader = this .metadataReaderFactory .getMetadataReader (memberClassName );
169
168
AnnotationMetadata memberClassMetadata = reader .getAnnotationMetadata ();
170
- if (isConfigurationCandidate (memberClassMetadata )) {
169
+ if (ConfigurationClassUtils . isConfigurationCandidate (memberClassMetadata )) {
171
170
processConfigurationClass (new ConfigurationClass (reader , null ));
172
171
}
173
172
}
@@ -204,7 +203,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
204
203
205
204
// process any @Import annotations
206
205
List <Map <String , Object >> allImportAttribs =
207
- AnnotationUtils . findAllAnnotationAttributes (Import .class , metadata .getClassName (), true , metadataReaderFactory );
206
+ findAllAnnotationAttributes (Import .class , metadata .getClassName (), true );
208
207
for (Map <String , Object > importAttribs : allImportAttribs ) {
209
208
processImport (configClass , (String []) importAttribs .get ("value" ), true );
210
209
}
@@ -229,6 +228,48 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
229
228
}
230
229
}
231
230
231
+
232
+ /**
233
+ * Return a list of attribute maps for all declarations of the given annotation
234
+ * on the given annotated class using the given MetadataReaderFactory to introspect
235
+ * annotation metadata. Meta-annotations are ordered first in the list, and if the
236
+ * target annotation is declared directly on the class, its map of attributes will be
237
+ * ordered last in the list.
238
+ * @param targetAnnotation the annotation to search for, both locally and as a meta-annotation
239
+ * @param annotatedClassName the class to inspect
240
+ * @param classValuesAsString whether class attributes should be returned as strings
241
+ */
242
+ private List <Map <String , Object >> findAllAnnotationAttributes (
243
+ Class <? extends Annotation > targetAnnotation , String annotatedClassName ,
244
+ boolean classValuesAsString ) throws IOException {
245
+
246
+ List <Map <String , Object >> allAttribs = new ArrayList <Map <String , Object >>();
247
+
248
+ MetadataReader reader = this .metadataReaderFactory .getMetadataReader (annotatedClassName );
249
+ AnnotationMetadata metadata = reader .getAnnotationMetadata ();
250
+ String targetAnnotationType = targetAnnotation .getName ();
251
+
252
+ for (String annotationType : metadata .getAnnotationTypes ()) {
253
+ if (annotationType .equals (targetAnnotationType )) {
254
+ continue ;
255
+ }
256
+ MetadataReader metaReader = this .metadataReaderFactory .getMetadataReader (annotationType );
257
+ Map <String , Object > targetAttribs =
258
+ metaReader .getAnnotationMetadata ().getAnnotationAttributes (targetAnnotationType , classValuesAsString );
259
+ if (targetAttribs != null ) {
260
+ allAttribs .add (targetAttribs );
261
+ }
262
+ }
263
+
264
+ Map <String , Object > localAttribs =
265
+ metadata .getAnnotationAttributes (targetAnnotationType , classValuesAsString );
266
+ if (localAttribs != null ) {
267
+ allAttribs .add (localAttribs );
268
+ }
269
+
270
+ return allAttribs ;
271
+ }
272
+
232
273
private void processImport (ConfigurationClass configClass , String [] classesToImport , boolean checkForCircularImports ) throws IOException {
233
274
if (checkForCircularImports && this .importStack .contains (configClass )) {
234
275
this .problemReporter .error (new CircularImportProblem (configClass , this .importStack , configClass .getMetadata ()));
0 commit comments