0

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.

Five
  • 378
  • 2
  • 19

1 Answers1

0

This answer was posted previously: Error creating bean with name 'liquibase' defined in class path resource ... /config/DatabaseConfiguration.class

I had the same problem. My solution is this way:

     Open ;
     *Database Tables (mySql or postgresql or another)
     *databasechangeloglock Table

     Change;
     *Locked=false

I reached the solution in this way. I hope it solves your problem.

tabbyfoo
  • 355
  • 1
  • 8