java 通过 maven 和 spring 使用 liquibase 文件路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16605099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using liquibase file paths via both maven and spring
提问by Alexandr
I update scheme and initial data in spring context using the following beean:
我使用以下 bean 在 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>
I also use Maven liquibase plugin to generate sql scripts in order to see what tables are created and etc.
我还使用 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>
The db.changelog-master.xml
file includes child liquibase changelog files. The problem, how to refer to them from the master. When I use Spring I have to use the following path via classpath:
该db.changelog-master.xml
文件包括子 liquibase 更改日志文件。问题,如何从高手参考他们。当我使用 Spring 时,我必须通过类路径使用以下路径:
<include file="classpath:/db/changelog/db.changelog-1.0.xml"/>
When Maven is used, the path is:
使用Maven时,路径为:
<include file="src/main/resources/db/changelog/db.changelog-1.0.xml"/>
I'd like to have the same configuration for both cases. How can I archive it?
我想为这两种情况使用相同的配置。我该如何存档?
采纳答案by Rolf
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.
为了解决这个问题,我只是向 Liquibase 推送了一个补丁:https: //github.com/liquibase/liquibase/pull/187。这应该在 3.0.6-SNAPSHOT 中合并,因此很快就会在 3.0.6 中可用。
With this change, you can now configure SpringLiquibase
with this additional line:
通过此更改,您现在可以SpringLiquibase
使用此附加行进行配置:
<property name="ignoringClasspathPrefix" value="true" />
Another example/usecase requiring this change can be found here: https://github.com/LateralThoughts/spring-liquibase-extensions.
可以在此处找到另一个需要此更改的示例/用例:https: //github.com/LateralThoughts/spring-liquibase-extensions。
回答by Igor Vash
I think if you change your Maven path from
我想如果你改变你的Maven路径
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
to
到
<changeLogFile>db/changelog/db.changelog-master.xml</changeLogFile>
and update db.changelog-master.xml file for all included files to use path relative to src/main/resources directory, it will fix the problem.
并更新所有包含文件的 db.changelog-master.xml 文件以使用相对于 src/main/resources 目录的路径,它将解决问题。
I solved this problem by using the same path to changeLog files in Spring, maven and integration test which call Liquibase. All my changelog files are located under /src/main/resources/db directory in one of the Maven modules within a project.
我通过在调用 Liquibase 的 Spring、maven 和集成测试中使用相同的更改日志文件路径解决了这个问题。我的所有更改日志文件都位于项目中 Maven 模块之一的 /src/main/resources/db 目录下。
Maven profile which runs Liquibase, notice path: db/masterChangeLog.xml
运行 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>
db/masterChangeLog.xml file includes these files:
db/masterChangeLog.xml 文件包括以下文件:
<include file="db/install.xml"/>
<include file="db/update.xml"/>
db/install.xml file includes other changelog files (so does update.xml):
db/install.xml 文件包括其他变更日志文件(update.xml 也是如此):
<includeAll path="db/install/seq"/>
<includeAll path="db/install/tab"/>
<includeAll path="db/install/cst"/>
<includeAll path="db/latest/vw" />
Spring context executes the same set of db scripts upon app startup as follows:
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>
回答by user2164990
Specify the logicalFilePath attribute in each databaseChangeLog file. See http://www.liquibase.org/documentation/databasechangelog.html
在每个 databaseChangeLog 文件中指定 logicalFilePath 属性。见http://www.liquibase.org/documentation/databasechangelog.html
回答by Elias Mueller
The Maven Plugin has the configuration property changeLogDirectory in recent versions.
Maven 插件在最新版本中具有配置属性 changeLogDirectory。
Hence setting <changeLogDirectory>src/main/resources</changeLogDirectory>
should achieve what you want.
因此设置<changeLogDirectory>src/main/resources</changeLogDirectory>
应该达到你想要的。