简体   繁体   English

弹簧靴中的多个liquibase配置

[英]Multiple liquibase configurations in spring boot

I have spring boot application which use 2 databases. 我有春季启动应用程序,使用2个数据库。 I defined 2 configurations providing specified datasources. 我定义了2个提供指定数据源的配置。 I want to have that datasources managed separately by liquibase. 我想让liquibase单独管理这些数据源。 I defined 2 separated changelog files. 我定义了2个单独的更改日志文件。

The problem is that I can't define 2 separate beans for liquibase. 问题是我无法为liquibase定义2个单独的bean。

Here are my config 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 config i get following error while running appliction: 使用此配置,我在运行应用程序时遇到以下错误:

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] o.s.boot.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] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
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 multiple liquibase beans for different datasources? 那么,是否可以为不同的数据源定义多个liquibase bean?

there are two options: 有两种选择:

  1. you define a bean named liquibase to let spring-boot integrated process to update your schema on you first DS. 你定义了一个名为liquibase的bean,让spring-boot集成进程在你的第一个DS上更新你的模式。 You have to handle the second one by hand 你必须手动处理第二个

  2. you disable liquibase automatic update at startup with 你在启动时禁用liquibase自动更新

enabled: false 启用:false

and define your way DS and liquibase beans to update your two databases 并定义DS和liquibase bean更新两个数据库的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM