@ -371,10 +371,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
sbr . registerSingleton ( IMPORT_REGISTRY_BEAN_NAME , parser . getImportRegistry ( ) ) ;
sbr . registerSingleton ( IMPORT_REGISTRY_BEAN_NAME , parser . getImportRegistry ( ) ) ;
}
}
if ( this . metadataReaderFactory instanceof CachingMetadataReaderFactory ) {
if ( this . metadataReaderFactory instanceof CachingMetadataReaderFactory cachingMetadataReaderFactory ) {
// Clear cache in externally provided MetadataReaderFactory; this is a no-op
// Clear cache in externally provided MetadataReaderFactory; this is a no-op
// for a shared cache since it'll be cleared by the ApplicationContext.
// for a shared cache since it'll be cleared by the ApplicationContext.
( ( C achingMetadataReaderFactory) this . metadataReaderFactory ) . clearCache ( ) ;
c achingMetadataReaderFactory. clearCache ( ) ;
}
}
}
}
@ -392,33 +392,30 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
Object configClassAttr = beanDef . getAttribute ( ConfigurationClassUtils . CONFIGURATION_CLASS_ATTRIBUTE ) ;
Object configClassAttr = beanDef . getAttribute ( ConfigurationClassUtils . CONFIGURATION_CLASS_ATTRIBUTE ) ;
AnnotationMetadata annotationMetadata = null ;
AnnotationMetadata annotationMetadata = null ;
MethodMetadata methodMetadata = null ;
MethodMetadata methodMetadata = null ;
if ( beanDef instanceof AnnotatedBeanDefinition ) {
if ( beanDef instanceof AnnotatedBeanDefinition annotatedBeanDefinition ) {
AnnotatedBeanDefinition annotatedBeanDefinition = ( AnnotatedBeanDefinition ) beanDef ;
annotationMetadata = annotatedBeanDefinition . getMetadata ( ) ;
annotationMetadata = annotatedBeanDefinition . getMetadata ( ) ;
methodMetadata = annotatedBeanDefinition . getFactoryMethodMetadata ( ) ;
methodMetadata = annotatedBeanDefinition . getFactoryMethodMetadata ( ) ;
}
}
if ( ( configClassAttr ! = null | | methodMetadata ! = null ) & & beanDef instanceof AbstractBeanDefinition ) {
if ( ( configClassAttr ! = null | | methodMetadata ! = null ) & &
( beanDef instanceof AbstractBeanDefinition abd ) & & ! abd . hasBeanClass ( ) ) {
// Configuration class (full or lite) or a configuration-derived @Bean method
// Configuration class (full or lite) or a configuration-derived @Bean method
// -> eagerly resolve bean class at this point, unless it's a 'lite' configuration
// -> eagerly resolve bean class at this point, unless it's a 'lite' configuration
// or component class without @Bean methods.
// or component class without @Bean methods.
AbstractBeanDefinition abd = ( AbstractBeanDefinition ) beanDef ;
boolean liteConfigurationCandidateWithoutBeanMethods =
if ( ! abd . hasBeanClass ( ) ) {
( ConfigurationClassUtils . CONFIGURATION_CLASS_LITE . equals ( configClassAttr ) & &
boolean liteConfigurationCandidateWithoutBeanMethods =
annotationMetadata ! = null & & ! ConfigurationClassUtils . hasBeanMethods ( annotationMetadata ) ) ;
( ConfigurationClassUtils . CONFIGURATION_CLASS_LITE . equals ( configClassAttr ) & &
if ( ! liteConfigurationCandidateWithoutBeanMethods ) {
annotationMetadata ! = null & & ! ConfigurationClassUtils . hasBeanMethods ( annotationMetadata ) ) ;
try {
if ( ! liteConfigurationCandidateWithoutBeanMethods ) {
abd . resolveBeanClass ( this . beanClassLoader ) ;
try {
}
abd . resolveBeanClass ( this . beanClassLoader ) ;
catch ( Throwable ex ) {
}
throw new IllegalStateException (
catch ( Throwable ex ) {
"Cannot load configuration class: " + beanDef . getBeanClassName ( ) , ex ) ;
throw new IllegalStateException (
"Cannot load configuration class: " + beanDef . getBeanClassName ( ) , ex ) ;
}
}
}
}
}
}
}
if ( ConfigurationClassUtils . CONFIGURATION_CLASS_FULL . equals ( configClassAttr ) ) {
if ( ConfigurationClassUtils . CONFIGURATION_CLASS_FULL . equals ( configClassAttr ) ) {
if ( ! ( beanDef instanceof AbstractBeanDefinition ) ) {
if ( ! ( beanDef instanceof AbstractBeanDefinition abd ) ) {
throw new BeanDefinitionStoreException ( "Cannot enhance @Configuration bean definition '" +
throw new BeanDefinitionStoreException ( "Cannot enhance @Configuration bean definition '" +
beanName + "' since it is not stored in an AbstractBeanDefinition subclass" ) ;
beanName + "' since it is not stored in an AbstractBeanDefinition subclass" ) ;
}
}
@ -428,7 +425,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
"is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " +
"is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " +
"return type: Consider declaring such methods as 'static'." ) ;
"return type: Consider declaring such methods as 'static'." ) ;
}
}
configBeanDefs . put ( beanName , ( AbstractBeanDefinition ) beanDef ) ;
configBeanDefs . put ( beanName , abd ) ;
}
}
}
}
if ( configBeanDefs . isEmpty ( ) | | NativeDetector . inNativeImage ( ) ) {
if ( configBeanDefs . isEmpty ( ) | | NativeDetector . inNativeImage ( ) ) {
@ -469,19 +466,19 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
public PropertyValues postProcessProperties ( @Nullable PropertyValues pvs , Object bean , String beanName ) {
public PropertyValues postProcessProperties ( @Nullable PropertyValues pvs , Object bean , String beanName ) {
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
// postProcessProperties method attempts to autowire other configuration beans.
// postProcessProperties method attempts to autowire other configuration beans.
if ( bean instanceof EnhancedConfiguration ) {
if ( bean instanceof EnhancedConfiguration enhancedConfiguration ) {
( ( EnhancedConfiguration ) bean ) . setBeanFactory ( this . beanFactory ) ;
enhancedConfiguration . setBeanFactory ( this . beanFactory ) ;
}
}
return pvs ;
return pvs ;
}
}
@Override
@Override
public Object postProcessBeforeInitialization ( Object bean , String beanName ) {
public Object postProcessBeforeInitialization ( Object bean , String beanName ) {
if ( bean instanceof ImportAware ) {
if ( bean instanceof ImportAware importAware ) {
ImportRegistry ir = this . beanFactory . getBean ( IMPORT_REGISTRY_BEAN_NAME , ImportRegistry . class ) ;
ImportRegistry ir = this . beanFactory . getBean ( IMPORT_REGISTRY_BEAN_NAME , ImportRegistry . class ) ;
AnnotationMetadata importingClass = ir . getImportingClassFor ( ClassUtils . getUserClass ( bean ) . getName ( ) ) ;
AnnotationMetadata importingClass = ir . getImportingClassFor ( ClassUtils . getUserClass ( bean ) . getName ( ) ) ;
if ( importingClass ! = null ) {
if ( importingClass ! = null ) {
( ( ImportAware ) bean ) . setImportMetadata ( importingClass ) ;
importAware . setImportMetadata ( importingClass ) ;
}
}
}
}
return bean ;
return bean ;