Basically, I would like to create beans by a list in my application.yml file.
I have to use multiple Liquibase changelog files within my Spring Boot application. Sadly, I can't do it in spring boot's configuration and I cannot put these files into one file, because the number of changelog files is always changing. Not an ideal situation but I cannot do anything against it now.
So, I figured out that defining Liquibase beans can help me out. Changelog files are getting used in the right order. But I want to add the files in the application.yml
file.
myconfig:
- pathToChangeLogFile_1
- pathToChangeLogFile_2
- pathToChangeLogFile_3
import java.sql.DataSource;
import liquibase.integration.spring.SpringLiquibase;
@Configuration
class LiquibaseConfiguration {
@Bean
public SpringLiquibase firstLiquibase(Datasource dataSource) {
SpringLiquibase liquibase = new SpringLiquibse();
liquibase.setDataSource(dataSource);
// ...
// other method calls
liquibase.setChangeLog("pathToChangeLogFile_1");
return liquibase;
}
@Bean
@DependsOn("firstLiquibase")
public SpringLiquibase secondLiquibase(Datasource dataSource) {
SpringLiquibase liquibase = new SpringLiquibse();
liquibase.setDataSource(dataSource);
// ...
// other method calls
liquibase.setChangeLog("pathToChangeLogFile_2");
return liquibase;
}
// Other beans and etc.
}
I don't want to rewrite my code every time a file is getting added. How would I create beans in spring by the application property config (list)? I thought of some kind of bean factory but I don't know how should I make sure my bean is getting the DataSource
there which is pretty straightforward with bean definition.
I looked at ImportBeanDefinitionRegistrar
, EnvironmentAware
, BeanFactoryAware
interfaces but I can't tell if I am on the good track.