[英]Spring boot - disable Liquibase at startup
I want to have Liquibase configured with my Spring Boot application, so I added dependencies to pom.xml
and set the path to master.xml
in application.properties
.我想用我的Spring Boot应用程序配置 Liquibase,所以我将依赖项添加到
pom.xml
并在application.properties
中将路径设置为master.xml
。 This works fine and Spring Boot runs Liquibase at startup.这工作正常并且Spring Boot在启动时运行Liquibase 。 The problem is that now I want to run Liquibase manually, not at startup of application.
问题是现在我想手动运行Liquibase ,而不是在应用程序启动时。 Should I completely disable auto-configuration for Liquibase or can I use it and only disable running evaluations at startup?
我应该完全禁用Liquibase的自动配置,还是可以使用它并仅在启动时禁用运行评估?
The relevant property name has changed between Spring versions: Spring 版本之间的相关属性名称已更改:
For Spring 4.xx : the liquibase.enabled=false
application property disables Liquibase.对于Spring 4.xx :
liquibase.enabled=false
应用程序属性禁用 Liquibase。
For Spring 5.xx : the spring.liquibase.enabled=false
application property disables Liquibase.对于Spring 5.xx :
spring.liquibase.enabled=false
应用程序属性禁用 Liquibase。
PS And for Flyway: PS和Flyway:
Spring 4.xx : flyway.enabled=false
Spring 4.xx :
flyway.enabled=false
Spring 5.xx : spring.flyway.enabled=false
弹簧 5.xx :
spring.flyway.enabled=false
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 解决了我的问题
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
:
@Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setShouldRun(false);
return liquibase;
}
There is one more programmatic approach.还有一种更程序化的方法。
@EnableAutoConfiguration(exclude = LiquibaseAutoConfiguration.class)
on Application main class在应用程序主类上
If you want to run Liquibase manually, you could use the liquibase maven plugin.如果你想手动运行 Liquibase,你可以使用 liquibase maven 插件。 Just add something like this to your pom.xml:
只需将这样的内容添加到您的 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 documentation for the configuration details.您可以查看插件文档以了解配置详细信息。
And don't use the liquibase support from Spring Boot, as it is only meant to be used in runtime.并且不要使用 Spring Boot 的 liquibase 支持,因为它仅用于运行时。 Just remove the liquibase starter and/or any related dependencies as you'll only need the maven plugin.
只需删除 liquibase starter 和/或任何相关的依赖项,因为您只需要 maven 插件。
You can use the spring.liquibase.enabled=true/false您可以使用 spring.liquibase.enabled=true/false
Whilst the documented Spring Boot solution is spring.liquibase.enabled=false
, it didn't work for me.虽然记录的 Spring 引导解决方案是
spring.liquibase.enabled=false
,但它对我不起作用。 To disable liquibase you can also use the following property:要禁用 liquibase,您还可以使用以下属性:
liquibase.shouldRun=false
I passed this as a command line parameter when launching the Spring Boot jar我在启动 Spring Boot jar 时将其作为命令行参数传递
-Dliquibase.shouldRun=false
see https://docs.liquibase.com/parameters/should-run.html见https://docs.liquibase.com/parameters/should-run.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.