Neale Upstone opened SPR-10396 and commented

An advantage of using Java config is that we get type-safe checking wiring and some resilience against refactoring going wrong, however the @DependsOn annotation only allows us to specify a String bean id.

For now, I am using @Autowired as a workaround as below (in preference to depending on a bean by String bean name):

@Configuration
@Import({
    LiquibaseConfig.class
})
public class PersistenceConfig {

    // used only to cause container to init SpringLiquibase bean 
    // before EntityManagerFactory bean. 
    @Autowired
    private SpringLiquibase dependsOnLiquibaseBean;

    @Autowired
    private DataSource dataSource;

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

        // use dataSource for creating EntityManagerFactory
        return factory;
    }

It would be nice to be able to have the order work without specifying @DependsOn("liquibase"), which is magic String territory.

Two options would help: - Making it the default behaviour that an @Import will cause the imported bean defs to init first (i.e when no @DependsOn specified) - Allowing @DependsOn to take a classes parameter as follows:

@Configuration
@Import({
    LiquibaseConfig.class
})
public class PersistenceConfig {

    @Autowired
    private DataSource dataSource;

    @Bean
    @DependsOn(classes=SpringLiquibase.class)
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

        // use dataSource for creating EntityManagerFactory
        return factory;
    }

Affects: 3.2.2

Comment From: spring-projects-issues

Neale Upstone commented

Has Spring 5 or Spring Boot brought a solution to this?

Comment From: spring-projects-issues

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Comment From: nealeu

How about Spring 6 for this one @jhoeller ?

    @DependsOn(classes=SpringLiquibase.class)

instead of

   @DependsOn("liquibase.integration.spring.SpringLiquibase")