@ -16,6 +16,8 @@
package org.springframework.context.annotation ;
package org.springframework.context.annotation ;
import static org.springframework.context.annotation.MetadataUtils.attributesFor ;
import java.io.IOException ;
import java.io.IOException ;
import java.lang.annotation.Annotation ;
import java.lang.annotation.Annotation ;
import java.util.ArrayList ;
import java.util.ArrayList ;
@ -34,6 +36,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.parsing.Location ;
import org.springframework.beans.factory.parsing.Location ;
import org.springframework.beans.factory.parsing.Problem ;
import org.springframework.beans.factory.parsing.Problem ;
import org.springframework.beans.factory.parsing.ProblemReporter ;
import org.springframework.beans.factory.parsing.ProblemReporter ;
import org.springframework.beans.factory.support.BeanDefinitionReader ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
import org.springframework.beans.factory.support.BeanDefinitionRegistry ;
import org.springframework.core.annotation.AnnotationAttributes ;
import org.springframework.core.annotation.AnnotationAttributes ;
import org.springframework.core.env.Environment ;
import org.springframework.core.env.Environment ;
@ -128,8 +131,9 @@ class ConfigurationClassParser {
protected void processConfigurationClass ( ConfigurationClass configClass ) throws IOException {
protected void processConfigurationClass ( ConfigurationClass configClass ) throws IOException {
AnnotationMetadata metadata = configClass . getMetadata ( ) ;
AnnotationMetadata metadata = configClass . getMetadata ( ) ;
if ( this . environment ! = null & & ProfileHelper . isProfileAnnotationPresent ( metadata ) ) {
if ( this . environment ! = null & & metadata . isAnnotated ( Profile . class . getName ( ) ) ) {
if ( ! this . environment . acceptsProfiles ( ProfileHelper . getCandidateProfiles ( metadata ) ) ) {
AnnotationAttributes profile = MetadataUtils . attributesFor ( metadata , Profile . class ) ;
if ( ! this . environment . acceptsProfiles ( profile . getStringArray ( "value" ) ) ) {
return ;
return ;
}
}
}
}
@ -172,11 +176,11 @@ class ConfigurationClassParser {
}
}
// process any @PropertySource annotations
// process any @PropertySource annotations
Map < String , Object > propertySourceAttributes =
AnnotationAttributes propertySource =
metadata . getAnnotationAttributes ( org . springframework . context . annotation . PropertySource . class . getName ( ) ) ;
attributesFor ( metadata , org . springframework . context . annotation . PropertySource . class ) ;
if ( propertySourceAttributes ! = null ) {
if ( propertySource ! = null ) {
String name = ( String ) propertySourceAttributes . get ( "name" ) ;
String name = propertySource . getString ( "name" ) ;
String [ ] locations = ( String [ ] ) propertySourceAttributes . get ( "value" ) ;
String [ ] locations = propertySource . getStringArray ( "value" ) ;
ClassLoader classLoader = this . resourceLoader . getClassLoader ( ) ;
ClassLoader classLoader = this . resourceLoader . getClassLoader ( ) ;
for ( String location : locations ) {
for ( String location : locations ) {
location = this . environment . resolveRequiredPlaceholders ( location ) ;
location = this . environment . resolveRequiredPlaceholders ( location ) ;
@ -188,34 +192,32 @@ class ConfigurationClassParser {
}
}
// process any @ComponentScan annotions
// process any @ComponentScan annotions
AnnotationAttributes componentScan = MetadataUtils . attributesFor ( metadata , ComponentScan . class ) ;
AnnotationAttributes componentScan = attributesFor ( metadata , ComponentScan . class ) ;
if ( componentScan ! = null ) {
if ( componentScan ! = null ) {
// the config class is annotated with @ComponentScan -> perform the scan immediately
// the config class is annotated with @ComponentScan -> perform the scan immediately
Set < BeanDefinitionHolder > scannedBeanDefinitions = this . componentScanParser . parse ( componentScan ) ;
Set < BeanDefinitionHolder > scannedBeanDefinitions = this . componentScanParser . parse ( componentScan ) ;
// check the set of scanned definitions for any further config classes and parse recursively if necessary
// check the set of scanned definitions for any further config classes and parse recursively if necessary
for ( BeanDefinitionHolder holder : scannedBeanDefinitions ) {
for ( BeanDefinitionHolder holder : scannedBeanDefinitions ) {
if ( ConfigurationClassUtils . checkConfigurationClassCandidate ( holder . getBeanDefinition ( ) , metadataReaderFactory ) ) {
if ( ConfigurationClassUtils . checkConfigurationClassCandidate ( holder . getBeanDefinition ( ) , this . metadataReaderFactory ) ) {
this . parse ( holder . getBeanDefinition ( ) . getBeanClassName ( ) , holder . getBeanName ( ) ) ;
this . parse ( holder . getBeanDefinition ( ) . getBeanClassName ( ) , holder . getBeanName ( ) ) ;
}
}
}
}
}
}
// process any @Import annotations
// process any @Import annotations
List < Map < String , Object > > allImportAttrib s =
List < AnnotationAttributes > import s =
findAllAnnotationAttributes ( Import . class , metadata . getClassName ( ) , true ) ;
findAllAnnotationAttributes ( Import . class , metadata . getClassName ( ) , true ) ;
for ( Map < String , Object > importAttribs : allImportAttrib s) {
for ( AnnotationAttributes importAnno : import s) {
processImport ( configClass , ( String [ ] ) importAttribs . get ( "value" ) , true ) ;
processImport ( configClass , importAnno . getStringArray ( "value" ) , true ) ;
}
}
// process any @ImportResource annotations
// process any @ImportResource annotations
if ( metadata . isAnnotated ( ImportResource . class . getName ( ) ) ) {
if ( metadata . isAnnotated ( ImportResource . class . getName ( ) ) ) {
String [ ] resources = ( String [ ] ) metadata . getAnnotationAttributes ( ImportResource . class . getName ( ) ) . get ( "value" ) ;
AnnotationAttributes importResource = attributesFor ( metadata , ImportResource . class ) ;
Class < ? > readerClass = ( Class < ? > ) metadata . getAnnotationAttributes ( ImportResource . class . getName ( ) ) . get ( "reader" ) ;
String [ ] resources = importResource . getStringArray ( "value" ) ;
if ( readerClass = = null ) {
Class < ? extends BeanDefinitionReader > readerClass =
throw new IllegalStateException ( "No reader class associated with imported resources: " +
importResource . getClass ( "reader" , BeanDefinitionReader . class ) ;
StringUtils . arrayToCommaDelimitedString ( resources ) ) ;
}
for ( String resource : resources ) {
for ( String resource : resources ) {
configClass . addImportedResource ( resource , readerClass ) ;
configClass . addImportedResource ( resource , readerClass ) ;
}
}
@ -239,11 +241,11 @@ class ConfigurationClassParser {
* @param annotatedClassName the class to inspect
* @param annotatedClassName the class to inspect
* @param classValuesAsString whether class attributes should be returned as strings
* @param classValuesAsString whether class attributes should be returned as strings
* /
* /
private List < Map < String , Object > > findAllAnnotationAttributes (
private List < AnnotationAttributes > findAllAnnotationAttributes (
Class < ? extends Annotation > targetAnnotation , String annotatedClassName ,
Class < ? extends Annotation > targetAnnotation , String annotatedClassName ,
boolean classValuesAsString ) throws IOException {
boolean classValuesAsString ) throws IOException {
List < Map < String , Object > > allAttribs = new ArrayList < Map < String , Object > > ( ) ;
List < AnnotationAttributes > allAttribs = new ArrayList < AnnotationAttributes > ( ) ;
MetadataReader reader = this . metadataReaderFactory . getMetadataReader ( annotatedClassName ) ;
MetadataReader reader = this . metadataReaderFactory . getMetadataReader ( annotatedClassName ) ;
AnnotationMetadata metadata = reader . getAnnotationMetadata ( ) ;
AnnotationMetadata metadata = reader . getAnnotationMetadata ( ) ;
@ -253,16 +255,17 @@ class ConfigurationClassParser {
if ( annotationType . equals ( targetAnnotationType ) ) {
if ( annotationType . equals ( targetAnnotationType ) ) {
continue ;
continue ;
}
}
MetadataReader metaReader = this . metadataReaderFactory . getMetadataReader ( annotationType ) ;
AnnotationMetadata metaAnnotations =
Map < String , Object > targetAttribs =
this . metadataReaderFactory . getMetadataReader ( annotationType ) . getAnnotationMetadata ( ) ;
metaReader . getAnnotationMetadata ( ) . getAnnotationAttributes ( targetAnnotationType , classValuesAsString ) ;
AnnotationAttributes targetAttribs =
AnnotationAttributes . fromMap ( metaAnnotations . getAnnotationAttributes ( targetAnnotationType , classValuesAsString ) ) ;
if ( targetAttribs ! = null ) {
if ( targetAttribs ! = null ) {
allAttribs . add ( targetAttribs ) ;
allAttribs . add ( targetAttribs ) ;
}
}
}
}
Map < String , Object > localAttribs =
AnnotationAttributes localAttribs =
metadata . getAnnotationAttributes ( targetAnnotationType , classValuesAsString ) ;
AnnotationAttributes . fromMap ( metadata . getAnnotationAttributes ( targetAnnotationType , classValuesAsString ) ) ;
if ( localAttribs ! = null ) {
if ( localAttribs ! = null ) {
allAttribs . add ( localAttribs ) ;
allAttribs . add ( localAttribs ) ;
}
}