问题描述
我使用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
Liqubase gradle配置和运行时库:
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.properties:
liquibase.changelog.path="classpath:src/main/resources/db/changelog/changes/"
liquibase.domain.package=ru.example.entities
应用程序配置 application.properties
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
我该如何解决?
更新:
更新了 resources / 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 = classpath: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/'
includeAll问题解决,如果将其替换为显式声明
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
解决方法
这是已提交的 liquibase 4.0.0问题 https://github.com/liquibase/liquibase/issues/1276 Liuquibase 3.10.2 正常工作。
,根据您的配置,liquibase看起来像是默认的classpath:/db/changelog/db.changelog-master.yaml
。
因此添加到您的application.properties
属性:
spring.liquibase.change-log=classpath:db/changelog/changes/<filename>
-注意在文件名中也添加文件名,以便它可以选择主要变更日志。