Liquibase-混合顺序的多个数据源 [英] Liquibase - multiple datasources in a mixed order

查看:191
本文介绍了Liquibase-混合顺序的多个数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据说我们可以使用下面的spring bean运行多个数据源

It is said that we can run multiple datasources with the below spring beans

<bean id="liquibase1" class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource1" />
      <property name="changeLog" value="classpath:db1-changelog.xml" />
 </bean>
 <bean id="liquibase2" class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource2" />
      <property name="changeLog" value="classpath:db2-changelog.xml" />
 </bean>

或具有以下pom.xml配置文件

or with the below pom.xml profiles

 <profiles>
        <profile>
            <id>db1</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <liquibase.url>jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
                <liquibase.driver>org.h2.Driver</liquibase.driver>
                <liquibase.username>user</liquibase.username>
                <liquibase.password>pass</liquibase.password>
            </properties>
        </profile>
        <profile>
            <id>db2</id>
            <properties>
                <liquibase.url>jdbc:h2:target/db2/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
                <liquibase.driver>org.h2.Driver</liquibase.driver>
                <liquibase.username>user</liquibase.username>
                <liquibase.password>pass</liquibase.password>
            </properties>
        </profile>
    </profiles>

如果我们需要以混合顺序运行脚本怎么办?就我而言,我需要先运行dataSource1,然后dataSource2,然后再次dataSource1,然后再次dataSource2

What if we need to run scripts in a mixed order? In my case I need to run one script from dataSource1, then dataSource2, then again dataSource1, then again dataSource2

推荐答案

我们可以通过多次使用相同的数据源并进行如下所示的Bean注入来实现此目的

We can do this by using the same data source many times with different bean injections as below

<bean id="liquibase1" class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource1" />
      <property name="changeLog" value="classpath:db1-changelog1.xml" />
 </bean>
 <bean id="liquibase2" depends-on="liquibase1" class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource2" />
      <property name="changeLog" value="classpath:db2-changelog1.xml" />
 </bean>
<bean id="liquibase3" depends-on="liquibase2"  class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource1" />
      <property name="changeLog" value="classpath:db1-changelog2.xml" />
 </bean>
<bean id="liquibase4" depends-on="liquibase3"  class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="dataSource2" />
      <property name="changeLog" value="classpath:db2-changelog2.xml" />
 </bean>

将这些bean定义放在单独的xml配置文件中并导入它是一个好主意

It is a good idea to put these bean definitions in a separate xml configuration file and import it

这篇关于Liquibase-混合顺序的多个数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆