春季启动:在Liquibase运行脚本之前实例化春季bean(embeddedDB)

时间:2019-02-27 16:03:11

标签: java spring spring-boot liquibase embedded-database

我们有一个使用关系数据库的spring-boot服务。直到不是,当在“本地”配置文件中运行spring boot应用程序时,我们在内存数据库中使用了H2。但是现在我们要旋转一个实际的内存数据库,而不是H2。

我们正在考虑在Spring bean中旋转嵌入式db,它将仅在本地配置文件中使用。

@Bean
@Profile("local")
public EmbeddedDb embeddedDb() {
   // spin new database here

}

在“本地”中启动应用程序时遇到问题。我们有一些liquibase脚本,在实例化创建新数据库的'embeddedDb'bean之前,应用程序始终尝试运行liquibase脚本。出现以下错误。

  

{“ @ timestamp”:“ 2019-02-       27T15:33:45.050 + 00:00“,” @ version“:” 1“,”消息“:”应用程序运行   失败”,“ logger_name”:“ org.springframework.boot.SpringApplication”,“ thread_name”:“ main”,“ level”:“ ERROR”,“ level_value”:40000,“ stack_trace”:“ org.springframework.beans。 factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / liquibase / LiquibaseAutoConfiguration $ LiquibaseConfiguration.class]中定义的名称为'liquibase'的bean时出错:

我们不能添加Spring的'depends-on',因为'liquibase'是自动配置的bean。

在运行liquibase脚本之前优化数据库的最佳方法是什么?

0 个答案:

没有答案