Multiple Liquibase configurations in spring boot

I have a spring boot application that uses 2 databases. I defined 2 configurations with given data sources. I want these data sources to be managed separately by lipibase. I defined 2 separate change files.

The problem is that I cannot define 2 separate beans for the liquid base.

Here are my configuration classes:

... public class CCSConfiguration { ... @Bean @ConfigurationProperties("ccs.liquibase") public LiquibaseProperties ccsLiquibaseProperties() { return new LiquibaseProperties(); } @Bean public SpringLiquibase ccsLiquibase(LiquibaseProperties liquibaseProperties) { ... } ... } ... public class CCAConfiguration { ... @ConfigurationProperties("cca.liquibase") public LiquibaseProperties ccaLiquibaseProperties() { return new LiquibaseProperties(); } @Bean public SpringLiquibase ccaLiquibase(LiquibaseProperties liquibaseProperties) { ... } ... } 

And properties:

 cca: liquibase: change-log: classpath:config/liquibase/cca/master.xml ccs: liquibase: change-log: classpath:config/liquibase/ccs/master.xml 

With this configuration, I get the following error when starting the application:

 2017-04-11 14:26:55.664 WARN 34292 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'liquibase' available 2017-04-11 14:26:55.711 WARN 34292 --- [ restartedMain] osboot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor]: Factory method 'cacheAdvisor' threw exception; nested exception is java.lang.NullPointerException) 2017-04-11 14:26:55.939 ERROR 34292 --- [ restartedMain] osbdLoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: A component required a bean named 'liquibase' that could not be found. Action: Consider defining a bean named 'liquibase' in your configuration. 

So, is it possible to define several lipibase beans for different data sources?

+5
source share
2 answers

There are two options:

  • you define a bean named liquidibase to integrate the spring-boot process to update your schema on the first DS. You must handle the second manually

  • you disable automatic update of liquibase at startup using

enabled: false

and define your DS and Liquibase beans path to upgrade two databases

+2
source

You can see my solution here . Actually in the post I am not writing about liquibase, but you can find an example for several instances of liquibase in the full source code on GitHub here .

0
source

Source: https://habr.com/ru/post/1266587/


All Articles