Java Spring boot - 在启动时禁用 Liquibase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37708145/
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
Spring boot - disable Liquibase at startup
提问by Gravian
I want to have Liquibase configured with my spring boot aplication, so I added dependencies to pom.xml and set the path to master.xml in application.properties. This works fine and Spring runs Liquibase at startup. The problem is that now I want to run Liquibase manually, not at startup of application. Should I completly disable Liquibase autoconfiguration or can i use it and only disable running evaluations at startup ?
我想用我的 Spring Boot 应用程序配置 Liquibase,所以我在 pom.xml 中添加了依赖项,并在 application.properties 中设置了 master.xml 的路径。这很好用,Spring 在启动时运行 Liquibase。问题是现在我想手动运行 Liquibase,而不是在应用程序启动时。我应该完全禁用 Liquibase 自动配置还是可以使用它并且只在启动时禁用运行评估?
回答by Cèsar
If you want to run Liquibase manually, you could use the liquibase maven plugin. Just add something like this to your pom.xml:
如果你想手动运行 Liquibase,你可以使用 liquibase maven 插件。只需将这样的内容添加到您的 pom.xml 中:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<changeLogFile>src/main/liquibase/master.xml</changeLogFile>
<propertyFile>src/main/liquibase/liquibase.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
You can take a look at the plugin documentationfor the configuration details.
您可以查看插件文档以了解配置详细信息。
And don't use the liquibase support from Spring Boot, as it is only meant to be used in runtime. Just remove the liquibase starter and/or any related dependencies as you'll only need the maven plugin.
并且不要使用 Spring Boot 的 liquibase 支持,因为它仅用于运行时。只需删除 liquibase starter 和/或任何相关的依赖项,因为您只需要 maven 插件。
回答by Sangram Jadhav
回答by Dávid Elek
I faced an issue where I wasn't able to disable Liquibase from properties for some reason, so this is how I disabled Liquibase with @Bean
annotation:
我遇到了一个问题,由于某种原因我无法从属性中禁用 Liquibase,所以这就是我使用@Bean
注释禁用 Liquibase 的方法:
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setShouldRun(false);
return liquibase;
}
回答by maruf571
If you see on the LiquibaseProperties, there is a prefix like
如果您在 LiquibaseProperties 上看到,则有一个前缀,例如
prefix = "spring.liquibase"
So, My suggestion is to use
所以,我的建议是使用
spring.liquibase.enabled=false
It solved my problem with spring boot 2.0.0.RC1
它用 spring boot 2.0.0.RC1 解决了我的问题
回答by Alex Shesterov
The relevant property name has changed between Spring versions:
Spring 版本之间的相关属性名称已更改:
For Spring 4.x.x: the
liquibase.enabled=false
application property disables Liquibase.For Spring 5.x.x: the
spring.liquibase.enabled=false
application property disables Liquibase.
对于Spring 4.xx:
liquibase.enabled=false
应用程序属性禁用 Liquibase。对于Spring 5.xx:
spring.liquibase.enabled=false
应用程序属性禁用 Liquibase。
P.S. And for Flyway:
PS和Flyway:
Spring 4.x.x:
flyway.enabled=false
Spring 5.x.x:
spring.flyway.enabled=false
弹簧 4.xx:
flyway.enabled=false
弹簧 5.xx:
spring.flyway.enabled=false