embedded-database-spring-test: BeanDefinitionOverrideException: Invalid bean definition with name 'dataSource' defined in null
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'dataSource' defined in null: Cannot register bean definition [Root bean: class [io.zonky.test.db.postgres.FlywayEmbeddedPostgresDataSourceFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'dataSource': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] bound.
at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:877)
at io.zonky.test.db.postgres.EmbeddedPostgresContextCustomizerFactory$PreloadableEmbeddedPostgresRegistrar.postProcessBeanDefinitionRegistry(EmbeddedPostgresContextCustomizerFactory.java:162)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:125)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:785)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:418)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:337)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
Java version - 11 Spring Boot - v2.1.0.M2 Spring - v5.1.0.RC2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (5 by maintainers)
Commits related to this issue
- #15 fix bean definition overriding that is disabled by default since Spring Boot 2.1.0 — committed to zonkyio/embedded-database-spring-test by tomix26 6 years ago
Thanks! solved my problem by adding property spring.main.allow-bean-definition-overriding=true
@tomix26 After adding the following property
And updating the flyway version to 5.1.4 (it didn’t work 5.0.7 because of ClassNotFoundException) I’ve got another error:
Thanks for reporting the issue. The problem is caused by the following change https://github.com/spring-projects/spring-boot/issues/13609 that disables bean overriding since Spring Boot 2.1.0.
Bean overriding can introduce major configuration issues and should not be enabled on non-test environments. You shouldn’t enable bean definition overriding. You have no control over which definition you’re going to get. You should fix the root cause of the problem instead by preventing the unwanted bean from being created.
@tomix26 thank you for your response. I have created an issue for flyway-spring-test