1616
1717package org .springframework .context .annotation ;
1818
19- import static org .springframework .context .annotation .ConfigurationClassUtils .isConfigurationCandidate ;
20-
2119import java .io .IOException ;
20+ import java .lang .annotation .Annotation ;
21+ import java .util .ArrayList ;
2222import java .util .Collections ;
2323import java .util .Comparator ;
2424import java .util .HashMap ;
3535import org .springframework .beans .factory .parsing .Problem ;
3636import org .springframework .beans .factory .parsing .ProblemReporter ;
3737import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
38- import org .springframework .core .annotation .AnnotationUtils ;
3938import org .springframework .core .env .Environment ;
4039import org .springframework .core .env .PropertySource ;
4140import org .springframework .core .io .ResourceLoader ;
42- import org .springframework .core .io .ResourcePropertySource ;
41+ import org .springframework .core .io .support . ResourcePropertySource ;
4342import org .springframework .core .type .AnnotationMetadata ;
4443import org .springframework .core .type .MethodMetadata ;
4544import org .springframework .core .type .StandardAnnotationMetadata ;
@@ -167,7 +166,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
167166 for (String memberClassName : metadata .getMemberClassNames ()) {
168167 MetadataReader reader = this .metadataReaderFactory .getMetadataReader (memberClassName );
169168 AnnotationMetadata memberClassMetadata = reader .getAnnotationMetadata ();
170- if (isConfigurationCandidate (memberClassMetadata )) {
169+ if (ConfigurationClassUtils . isConfigurationCandidate (memberClassMetadata )) {
171170 processConfigurationClass (new ConfigurationClass (reader , null ));
172171 }
173172 }
@@ -204,7 +203,7 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
204203
205204 // process any @Import annotations
206205 List <Map <String , Object >> allImportAttribs =
207- AnnotationUtils . findAllAnnotationAttributes (Import .class , metadata .getClassName (), true , metadataReaderFactory );
206+ findAllAnnotationAttributes (Import .class , metadata .getClassName (), true );
208207 for (Map <String , Object > importAttribs : allImportAttribs ) {
209208 processImport (configClass , (String []) importAttribs .get ("value" ), true );
210209 }
@@ -229,6 +228,48 @@ protected void doProcessConfigurationClass(ConfigurationClass configClass, Annot
229228 }
230229 }
231230
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+
232273 private void processImport (ConfigurationClass configClass , String [] classesToImport , boolean checkForCircularImports ) throws IOException {
233274 if (checkForCircularImports && this .importStack .contains (configClass )) {
234275 this .problemReporter .error (new CircularImportProblem (configClass , this .importStack , configClass .getMetadata ()));
0 commit comments