我有使用2个数据库的spring boot应用程序。我定义了2个提供指定数据源的配置。我想让liquibase单独管理这些数据源。我定义了2个单独的更改日志文件。
问题是我无法为liquibase定义2个单独的bean。
以下是我的配置类:
...
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) {
...
}
...
}
和属性:
cca:
liquibase:
change-log: classpath:config/liquibase/cca/master.xml
ccs:
liquibase:
change-log: classpath:config/liquibase/ccs/master.xml
使用此配置,我在运行应用程序时遇到以下错误:
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.
那么,是否可以为不同的数据源定义多个liquibase bean?
答案 0 :(得分:3)
有两种选择:
您定义了一个名为liquibase的bean,让spring-boot集成进程在您的第一个DS上更新您的架构。你必须手动处理第二个
您在启动时使用
已启用:false
并定义DS和liquibase bean更新两个数据库的方式