Skip to content

Dependency relationships created by AbstractDependsOnBeanFactoryPostProcessors cannot be overridden #18362

@jwenting

Description

@jwenting

When upgrading to Spring Boot 2.1.8-RELEASE from 2.1.7-RELEASE we now get a BeanCreationException that didn't happen before (no code was changed, only the Spring Boot version number in the pom file).

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseEntityManager' defined in class path resource [xxxxxx/config/DatabaseContext.class]: Circular depends-on relationship between 'baseEntityManager' and 'delayedFlywayInitializer'
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
 	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
 	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
 	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
 	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
 	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
 	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)

The bean definitions (in separate @Configuration annotated classes) are as follows:

    @Bean
    @Primary
    public LocalContainerEntityManagerFactoryBean baseEntityManager() {
        return EntityManagerFactoryBuilder.buildEntityManagerFactory(dataSource(), "xxxxxx.config.MySQLCustomDialect",
                "nl.triopsys.aangetekendmailen.domain", JSR310_PACKAGE);
    }
    @Bean
    @DependsOn("baseEntityManager")
    FlywayMigrationInitializer delayedFlywayInitializer(Flyway flyway) {
        return new FlywayMigrationInitializer(flyway, null);
    }

Again, in Spring Boot 2.1.7 (and earlier, this code was originally written against Spring Boot 1.3 and has been working in production for several years) this works as expected, the delayedFlywayInitializer gets created after the baseEntityManager (in order to run Flyway migrations after Hibernate is done with its schema updates).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions