Spring boot - disable Liquibase at startup

前端 未结 6 1902
一生所求
一生所求 2021-02-05 00:45

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

相关标签:
6条回答
  • 2021-02-05 00:47

    There is one more programmatic approach.

    @EnableAutoConfiguration(exclude = LiquibaseAutoConfiguration.class)

    on Application main class

    0 讨论(0)
  • 2021-02-05 00:49

    If you see on the LiquibaseProperties, there is a prefix like

     prefix = "spring.liquibase"
    

    So, My suggestion is to use

    spring.liquibase.enabled=false
    

    It solved my problem with spring boot 2.0.0.RC1

    0 讨论(0)
  • 2021-02-05 00:59

    If you want to run Liquibase manually, you could use the liquibase maven plugin. Just add something like this to your 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. Just remove the liquibase starter and/or any related dependencies as you'll only need the maven plugin.

    0 讨论(0)
  • 2021-02-05 01:02

    Add liquibase.enabled=false in your application.properties file

    Reference

    But if you don't want to use liquibase from application anymore, remove liquibase starter altogether from pom.

    0 讨论(0)
  • 2021-02-05 01:02

    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:

    @Bean
    public SpringLiquibase liquibase() {
      SpringLiquibase liquibase = new SpringLiquibase();
      liquibase.setShouldRun(false);
      return liquibase;
    }
    
    0 讨论(0)
  • 2021-02-05 01:14

    The relevant property name has changed between Spring versions:

    • 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.


    P.S. And for Flyway:

    • Spring 4.x.x: flyway.enabled=false

    • Spring 5.x.x: spring.flyway.enabled=false

    0 讨论(0)
提交回复
热议问题