Ale*_*ndr 15 java spring liquibase maven
我使用以下beean在spring上下文中更新方案和初始数据:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="dataSource" />
<property name="changeLog" value="classpath:db/changelog/db.changelog-master.xml" />
<property name="dropFirst" value="true" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我还使用Maven liquibase插件生成sql脚本,以便查看创建了哪些表等.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.5</version>
<configuration>
<!--mvn initialize liquibase:updateSQL-->
<propertyFile>src/main/resources/db/config/liquibase-gensql-data-access.properties</propertyFile>
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
该db.changelog-master.xml文件包含子liquibase changelog文件.问题是,如何从主人那里引用它们.当我使用Spring时,我必须通过classpath使用以下路径:
<include file="classpath:/db/changelog/db.changelog-1.0.xml"/>
Run Code Online (Sandbox Code Playgroud)
使用Maven时,路径是:
<include file="src/main/resources/db/changelog/db.changelog-1.0.xml"/>
Run Code Online (Sandbox Code Playgroud)
我想对两种情况都有相同的配置.我该如何存档?
Igo*_*ash 10
我想如果你改变你的Maven路径
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
Run Code Online (Sandbox Code Playgroud)
至
<changeLogFile>db/changelog/db.changelog-master.xml</changeLogFile>
Run Code Online (Sandbox Code Playgroud)
并更新所有包含文件的db.changelog-master.xml文件以使用相对于src/main/resources目录的路径,它将解决问题.
我通过在Spring,maven和集成测试中使用相同的路径来更改日志文件来解决这个问题,该测试调用了Liquibase.我的所有更改日志文件都位于项目中某个Maven模块的/ src/main/resources/db目录下.
运行Liquibase的Maven配置文件,通知路径:db/masterChangeLog.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>*** Install a last major release version of db ***</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>db/masterChangeLog.xml</changeLogFile>
<contexts>dbBuildContext, dmlDevContext</contexts>
<propertyFile>db/liquibase-${user.name}.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<logging>debug</logging>
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)
db/masterChangeLog.xml文件包含以下文件:
<include file="db/install.xml"/>
<include file="db/update.xml"/>
Run Code Online (Sandbox Code Playgroud)
db/install.xml文件包含其他changelog文件(update.xml也是如此):
<includeAll path="db/install/seq"/>
<includeAll path="db/install/tab"/>
<includeAll path="db/install/cst"/>
<includeAll path="db/latest/vw" />
Run Code Online (Sandbox Code Playgroud)
Spring上下文在应用启动时执行相同的db脚本集,如下所示:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="baseCostManagementDataSource" />
<property name="changeLog" value="classpath:db/masterChangelog.xml" />
<property name="contexts" value="dbBuildContext, dmlDevContext" />
</bean>
Run Code Online (Sandbox Code Playgroud)
I commented on Igor's answer, his solution does not seem to work.
In order to solve this, I just pushed a patch to Liquibase: https://github.com/liquibase/liquibase/pull/187. This should be merged in 3.0.6-SNAPSHOT and therefore shortly available in 3.0.6.
With this change, you can now configure SpringLiquibase with this additional line:
<property name="ignoringClasspathPrefix" value="true" />
Run Code Online (Sandbox Code Playgroud)
Another example/usecase requiring this change can be found here: https://github.com/LateralThoughts/spring-liquibase-extensions.
| 归档时间: |
|
| 查看次数: |
12814 次 |
| 最近记录: |