Switching to Spring-Boot 2.1.0.RELEASE bean overriding is not allowed by default anymore. This causes following error:
...
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'org.springframework.context.config.internalBeanConfigurerAspect' defined in null: Cannot register bean definition [Root bean: class [org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=aspectOf; initMethodName=null; destroyMethodName=null] for bean 'org.springframework.context.config.internalBeanConfigurerAspect': There is already [Root bean: class [org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=aspectOf; initMethodName=null; destroyMethodName=null] bound.
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:894)
at org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanConfigurerAspectIfNecessary(JpaAuditingRegistrar.java:135)
at org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanDefinitions(JpaAuditingRegistrar.java:88)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:364)
at java.util.LinkedHashMap.forEach(Unknown Source)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:363)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:145)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
... 25 more
With some debugging I found that org.springframework.data.jpa.repository.config.JpaAuditingRegistrar.registerBeanConfigurerAspectIfNecessary(BeanDefinitionRegistry)
will be called twice. Would be nice if someone could explain this btw. Anyway the first if-statement in that method should recognize the bean of type AnnotationBeanConfigurerAspect
is already registered and does not lead to an OverrideException:
private void registerBeanConfigurerAspectIfNecessary(BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(BEAN_CONFIGURER_ASPECT_CLASS_NAME)) {
return;
}
registry.containsBeanDefinition
checks the key
in registry.definitionMap
for org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
. But the BeanDefinition
looks like this:
key = org.springframework.context.config.internalBeanConfigurerAspect
value = Bean of Type [org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect]
It seems that key
and value
are mixed up.
The failure is caused by a bug in Spring Data JPA that has been fixed but not yet released. It will be part of Spring Data Lovelace SR3 which will be included in Spring Boot 2.1.1.