Liquibase 4.0无法在罐子中启动



我使用Spring 2.3.3和Liquibase 4.0.0。当运行gradlew-bootRun时,它工作得很好,但当我运行编译的jar时,我会收到很多消息,比如:

2020-09-11 17:40:33.267  WARN 1 --- [           main] liquibase.integration                    : Cannot create filesystem for url jar:file:/app.jar!/BOOT-INF/lib/spring-aspects-5.2.8.RELEASE.jar!/: null
java.nio.file.FileSystemNotFoundException: null
...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfigurati
on.class]: Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: Error parsing classpath:/db/changelog/db.changelog-master.yaml

Liquibase渐变配置和运行库:

configurations {
liquibaseRuntime.extendsFrom runtime
compileOnly {
extendsFrom annotationProcessor
}
Properties liquibaseProps = new Properties()
liquibaseProps.load(new FileInputStream("src/main/resources/liquibase.properties"))
Properties applicationProps = new Properties()
applicationProps.load(new FileInputStream("src/main/resources/application.properties"))
liquibase {
activities {
main {
referenceUrl 'hibernate:spring:' + liquibaseProps.getProperty('liquibase.domain.package') + '?dialect=' + applicationProps.getProperty('spring.jpa.database-platform') + '&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
driver applicationProps.getProperty('spring.datasource.driver-class-name')
changeLogFile liquibaseProps.getProperty('liquibase.changelog.path') + migrationName() + '.yaml'
url applicationProps.getProperty('spring.datasource.url')
username applicationProps.getProperty('spring.datasource.username')
password applicationProps.getProperty('spring.datasource.password')
}
}
}
}

运行时:

liquibaseRuntime 'org.liquibase:liquibase-core:4.0.0'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.1.2'
liquibaseRuntime 'org.postgresql:postgresql'
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.0.0'
liquibaseRuntime sourceSets.main.output
liquibaseRuntime "ch.qos.logback:logback-core"
liquibaseRuntime "ch.qos.logback:logback-classic"
liquibaseRuntime 'org.yaml:snakeyaml'
liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-security'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-web'

液化糖。性质:

liquibase.changelog.path="classpath:src/main/resources/db/changelog/changes/"
liquibase.domain.package=ru.example.entities

应用程序配置应用程序属性

spring.application.name = "Example"
application.description = "Example"
application.version = 1.0

spring.jpa.database-platform = org.hibernate.dialect.PostgreSQL10Dialect
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.hibernate.naming.implicit-strategy = org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql:localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=qwerty

我该怎么修?

更新:

更新资源/db/changelog/db.changelog-master.yaml:

databaseChangeLog:
- includeAll:
path: classpath:db/changelog/changes/

更新了gradle:中的liquibase配置

liquibase {
activities {
main {
classpath "$projectDir/src/main/resources/db/changelog"
...

添加到application.properties:spring.liquibase.change-log=类路径:db/changelog/db.changelog-master.yaml

现在我仍然收到关于未找到jar依赖项的警告:

liquibase.integration                    : Cannot create filesystem for url jar:file:/app.jar!/BOOT-INF/lib/spring-aspects-5.2.8.RELEASE.jar!/: null
java.nio.file.FileSystemNotFoundException: null
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:172) ~[jdk.zipfs:na]

仍未找到嵌入式变更集:

Could not find directory or directory was empty for includeAll 'db/changelog/changes/'

include的问题如果用显式声明替换它,则所有修复:

databaseChangeLog:
- include:
file: changes/20200829022849_default.yaml
relativeToChangelogFile: true

更新2这是存储库上的链接https://github.com/dekar91/liquibase_ex我这样构建和启动应用程序:

./gradleew bootJar
java -jar example-0.0.1-SNAPSHOT.jar

这是一个已提交的liquibase4.0.0版本https://github.com/liquibase/liquibase/issues/1276Liuquibase3.10.2工作正常。

从您的配置来看,liquibase似乎是默认的classpath:/db/changelog/db.changelog-master.yaml

因此,添加到您的application.properties属性:

spring.liquibase.change-log=classpath:db/changelog/changes/<filename>-注意添加文件名,这样它就可以选择主变更日志。

最新更新