Liquibase和Spring集成

lie*_*ran 3 spring liquibase

我正在尝试将Liquibase与Spring集成(请参阅此http://www.liquibase.org/documentation/spring.html),目前我手动使用Liquibase,我想更新数据库作为应用程序初始化的一部分(战争)

一切运行良好,预计Liquibase Spring Bean会很多其他bean(例如Spring Security beans)之后加载.

我如何确保在所有其他bean之前加载Liquibase bean?考虑到目前Liquibase bean有它自己的Spring配置文件.

谢谢.

小智 5

我偶然发现了同样的问题并用@DependsOn注释解决了它.它有助于spring以有意义的顺序解决依赖关系,并且应该是相当不言自明的.

示例代码:

@DependsOn("liquibase")
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private DataSource dataSource;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.jdbcAuthentication()
                .dataSource(dataSource)
                // ... 
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // ...
    }
}
Run Code Online (Sandbox Code Playgroud)

或者,存在depends-on基于XML的配置的属性.