Exclude SharedMetadataReaderFactoryContextInitializer from AOT contexts
SharedMetadataReaderFactoryContextInitializer exposes an additional bean post processor that is only relevant when parsing the bean factory, auto-configurations in particular. Given that this does not happen in an AOT-optimized context, this commit excludes the bean and makes sure the initializer does not do anything at runtime. Closes gh-33216
This commit is contained in:
parent
55ba5a5074
commit
cb1ee205ea
|
|
@ -18,11 +18,13 @@ package org.springframework.boot.autoconfigure;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.springframework.aot.AotDetector;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
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.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
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.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
||||||
|
import org.springframework.beans.factory.support.RegisteredBean;
|
||||||
import org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory;
|
import org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory;
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
import org.springframework.context.ApplicationContextInitializer;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
@ -51,14 +54,17 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
class SharedMetadataReaderFactoryContextInitializer
|
class SharedMetadataReaderFactoryContextInitializer implements
|
||||||
implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
|
ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered, BeanRegistrationExcludeFilter {
|
||||||
|
|
||||||
public static final String BEAN_NAME = "org.springframework.boot.autoconfigure."
|
public static final String BEAN_NAME = "org.springframework.boot.autoconfigure."
|
||||||
+ "internalCachingMetadataReaderFactory";
|
+ "internalCachingMetadataReaderFactory";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||||
|
if (AotDetector.useGeneratedArtifacts()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
BeanFactoryPostProcessor postProcessor = new CachingMetadataReaderFactoryPostProcessor(applicationContext);
|
BeanFactoryPostProcessor postProcessor = new CachingMetadataReaderFactoryPostProcessor(applicationContext);
|
||||||
applicationContext.addBeanFactoryPostProcessor(postProcessor);
|
applicationContext.addBeanFactoryPostProcessor(postProcessor);
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +74,11 @@ class SharedMetadataReaderFactoryContextInitializer
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
|
||||||
|
return BEAN_NAME.equals(registeredBean.getBeanName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link BeanDefinitionRegistryPostProcessor} to register the
|
* {@link BeanDefinitionRegistryPostProcessor} to register the
|
||||||
* {@link CachingMetadataReaderFactory} and configure the
|
* {@link CachingMetadataReaderFactory} and configure the
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,6 @@ org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingP
|
||||||
|
|
||||||
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
||||||
org.springframework.boot.autoconfigure.flyway.ResourceProviderCustomizerBeanRegistrationAotProcessor
|
org.springframework.boot.autoconfigure.flyway.ResourceProviderCustomizerBeanRegistrationAotProcessor
|
||||||
|
|
||||||
|
org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter=\
|
||||||
|
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer
|
||||||
Loading…
Reference in New Issue