You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The project is compiled with native profile and started with -Dspring.aot.enabled=true, and I got following exception.
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'l1ServiceA' defined in com.xmbsmdsj.springbootdemo.NativeConfiguration: @Bean definition illegally overridden by existing bean definition: Root bean: class [com.xmbsmdsj.springbootdemo.L1ServiceA]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=l1ServiceA; initMethodNames=null; destroyMethodNames=null
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.isOverriddenByExistingDefinition(ConfigurationClassBeanDefinitionReader.java:319) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:204) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:410) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:283) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:344) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:145) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:745) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[spring-context-6.0.3.jar:6.0.3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[spring-boot-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-3.0.1.jar:3.0.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[spring-boot-3.0.1.jar:3.0.1]
at com.xmbsmdsj.springbootdemo.SpringBootDemoApplication.main(SpringBootDemoApplication.java:11) ~[classes/:na]
I dropped a breakpoint in following method of ClassPathBeanDefinitionScanner, observing that @configuration classes seem to be scanned even if bean definition registrations are generated at build-time.
public int scan(String... basePackages) {
int beanCountAtScanStart = this.registry.getBeanDefinitionCount();
doScan(basePackages);
// It looks like the issue was due to this block
if (this.includeAnnotationConfig) {
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
}
return (this.registry.getBeanDefinitionCount() - beanCountAtScanStart);
}
The text was updated successfully, but these errors were encountered:
wylswz
changed the title
Bean definition overridden when spring.aot.enabled=true
Bean definition overridden when spring.aot.enabled=true in spring boot 3.0
Jan 28, 2023
Thanks for your contributing!
Probably, this issue can be fix to use the AotDetector#useGeneratedArtifacts() instead of NativeDetector.inNativeImage() for set the includeAnnotationConfig to false on the ClassPathMapperScanner.
Fixesmybatisgh-780
Fix to use the AotDetector#useGeneratedArtifacts() instead of NativeDetector.inNativeImage() for set the includeAnnotationConfig to false on the ClassPathMapperScanner
original discussion
The project is compiled with native profile and started with -Dspring.aot.enabled=true, and I got following exception.
I dropped a breakpoint in following method of ClassPathBeanDefinitionScanner, observing that @configuration classes seem to be scanned even if bean definition registrations are generated at build-time.
Heres the code to reproduce
https://github.com/spring-projects/spring-boot/files/10471672/spring-boot-demo.zip
The text was updated successfully, but these errors were encountered: