【问题标题】:Liquibase changelog not running in spring bootLiquibase 更改日志未在 Spring Boot 中运行
【发布时间】:2019-05-30 04:23:35
【问题描述】:

我正在尝试运行 springboot api 并使用 liquibase 配置数据库。

这里的问题是我遵循了几个教程中描述的所有步骤,但从未执行过更改日志。

代码:

Gradle 配置:

group = 'com.strixtools'
version = '0.0.1-SNAPSHOT'

description = """Strix Tools"""

buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
         classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE"
         classpath "gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.20.1"
    }
 }

group = 'strixtools'

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.palantir.docker'

bootJar {
    baseName = 'gs-spring-boot-docker'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    configurations.all {
        exclude module: "spring-boot-starter-logging"
        exclude module: "logback-classic"
    }
    compile ('org.springframework.boot:spring-boot-starter:2.1.1.RELEASE')
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'2.1.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'2.1.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version:'2.1.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'2.1.1.RELEASE'
    compile group: 'org.springframework.security.oauth.boot', name: 'spring-security-oauth2-autoconfigure', version: '2.1.1.RELEASE'
    compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4'
    compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.9.0'
    compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version:'2.6.5'
    compile group: 'org.liquibase', name: 'liquibase-core'
    compile group: 'com.h2database', name: 'h2', version:'1.4.196'
    runtime group: 'org.postgresql', name: 'postgresql'
    testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'2.1.1.RELEASE')

    compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j2', version:'2.1.1.RELEASE'

}

task stage {
    dependsOn build
}

task unpack(type: Copy) {
    dependsOn bootJar
    from(zipTree(tasks.bootJar.outputs.files.singleFile))
    into("build/dependency")
}
docker {
    name "${project.group}/${bootJar.baseName}"
    copySpec.from(tasks.unpack.outputs).into("dependency")
    buildArgs(['DEPENDENCY': "dependency"])
}

应用程序.yml

strix-api:
   host: https://aaa.com
   client: asdasdasfasdf
   secret: afadsfsdaf
   user: afdadsfsadf
   pass: afadsfsdafsdaf

---  

弹簧: 个人资料:本地

  datasource:
    url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    username: sa
    password:

  liquibase:
    change-log: classpath:db/changelog-master.xml
    enabled: true
    drop-first: true

  jpa:
    hibernate:
      ddl-auto: none
    show-sql: true
  h2:
    console:
      enabled: true

还有我的 SpringAplication 类

@SpringBootApplication
public class StrixToolsApplication {

     public static void main(String[] args) {
        SpringApplication.run(StrixToolsApplication.class, args);
    }

    //TODO: we should move this to another side
    @Bean(name = "messageSource")
    public ReloadableResourceBundleMessageSource messageSource() {
         ReloadableResourceBundleMessageSource messageBundle = new ReloadableResourceBundleMessageSource();
        messageBundle.setBasename("classpath:messages/messages");
        messageBundle.setDefaultEncoding("UTF-8");
        return messageBundle;
    }


    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

问题是 liquibase 永远不会执行。如果我将更改日志名称更改为其他名称,它甚至不会引发错误。

感谢您的帮助 问候

【问题讨论】:

    标签: spring spring-boot h2 liquibase


    【解决方案1】:

    在我的情况下,问题是我为 gradle 插件声明了一个依赖项,就像这样

    liquibaseRuntime("org.liquibase:liquibase-core:3.8.1")
    

    但不适用于运行时的 liquibase,就像这样

    runtimeOnly("org.liquibase:liquibase-core:3.8.1")
    

    【讨论】:

    • 我也是这样。
    【解决方案2】:

    也许您缺少正确版本的 liquibase。尝试使用 2.0.1。 这里有一个小示例:(您可以重构用于版本和组的表示法)。

        apply plugin: 'liquibase'
    
        plugins {
            id 'io.spring.dependency-management' version '1.0.5.RELEASE'
            id 'org.liquibase.gradle' version '2.0.1'
    
        }
    ependencies {
        implementation('org.springframework.boot:spring-boot-starter-actuator')
        implementation('org.springframework.boot:spring-boot-starter-web')
        implementation('org.springframework.boot:spring-boot-starter-security')
        implementation('org.springframework.boot:spring-boot-starter-data-jpa')
        implementation('org.springframework.boot:spring-boot-starter-validation')
        implementation('org.liquibase:liquibase-core')
        runtime 'mysql:mysql-connector-java'
    
        liquibaseRuntime group: 'org.liquibase', name: 'liquibase-core', version: liquibaseCoreVersion
        liquibaseRuntime group: 'org.liquibase', name: 'liquibase-groovy-dsl', version: liquibaseGroovyDslVersion
        liquibaseRuntime 'mysql:mysql-connector-java'
    
    }
    
    liquibase {
        activities {
            main {
                changeLogFile 'src/main/resources/db/liquibase-changelog.xml'
                url 'jdbc:mysql://' + System.env.DATABASE_HOST + ':' + System.env.DATABASE_PORT + '/' + System.env.DATABASE_NAME + '?useSSL=false'
                username System.env.DATABASE_USER
                password System.env.DATABASE_PASSWORD
                driver 'com.mysql.jdbc.Driver'
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      相关资源
      最近更新 更多