Reputation: 199
i am trying to integrate Liquibase with Spring (see this http://www.liquibase.org/documentation/spring.html ) currently i am using Liquibase manually, and i wanted to update the DB as part of the init of the application (war)
everything is working well expect the fact that Liquibase Spring Bean is loaded after a lot of other beans (e.g Spring Security beans).
how can i make sure that Liquibase bean is loaded before all the other beans ? consider that currently Liquibase bean have it's own Spring profile.
Thanks.
Upvotes: 4
Views: 2645
Reputation:
I just stumbled across the same problem and solved it with the @DependsOn annotation. It helps spring to resolve dependencies in an order that makes sense and should be fairly self-explanatory.
Example code:
@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 {
// ...
}
}
Alternatively there is the depends-on
attribute for XML based configuration.
Upvotes: 5