diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializer.java index f6dfdeb9e0..c8843e827e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/SharedMetadataReaderFactoryContextInitializer.java @@ -18,11 +18,13 @@ package org.springframework.boot.autoconfigure; import java.util.function.Supplier; +import org.springframework.aot.AotDetector; import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -31,6 +33,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; +import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationListener; @@ -51,14 +54,17 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; * @author Phillip Webb * @author Dave Syer */ -class SharedMetadataReaderFactoryContextInitializer - implements ApplicationContextInitializer, Ordered { +class SharedMetadataReaderFactoryContextInitializer implements + ApplicationContextInitializer, Ordered, BeanRegistrationExcludeFilter { public static final String BEAN_NAME = "org.springframework.boot.autoconfigure." + "internalCachingMetadataReaderFactory"; @Override public void initialize(ConfigurableApplicationContext applicationContext) { + if (AotDetector.useGeneratedArtifacts()) { + return; + } BeanFactoryPostProcessor postProcessor = new CachingMetadataReaderFactoryPostProcessor(applicationContext); applicationContext.addBeanFactoryPostProcessor(postProcessor); } @@ -68,6 +74,11 @@ class SharedMetadataReaderFactoryContextInitializer return 0; } + @Override + public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) { + return BEAN_NAME.equals(registeredBean.getBeanName()); + } + /** * {@link BeanDefinitionRegistryPostProcessor} to register the * {@link CachingMetadataReaderFactory} and configure the diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/aot.factories b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/aot.factories index 52d9ac0211..1713445618 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/aot.factories +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/spring/aot.factories @@ -7,3 +7,6 @@ org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingP org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\ org.springframework.boot.autoconfigure.flyway.ResourceProviderCustomizerBeanRegistrationAotProcessor + +org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=\ +org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer \ No newline at end of file