【发布时间】:2019-08-30 23:35:24
【问题描述】:
我正在学习 Liquibase 和 Spring Boot,所以我用Spring Initializr 创建了一个简单的项目。
在我添加的 POM.xml 文件中:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<propertyFile>src/main/resources/application.properties</propertyFile>
</configuration>
</plugin>
我已将 application.properties 指定为属性文件,因此我的应用程序的所有配置都可以在单个文件中进行。
当我从 IntelliJ 运行任何 liquibase-maven-plugin 任务时,我会收到不同的错误,这是一个运行 changeLogSync 任务的示例:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:changelogSync (default-cli) on project simpleTest: The changeLogFile must be specified
如果我在 application.properties 中添加正确的键,我就能让它工作。
例如,我发现 liquibase-maven-plugin 不会读取 spring.datasource.url 属性,但它只会读取 url 属性。
因此,我的 application.properties 必须是类似的:
environment = JUnit
spring.datasource.url = jdbc:h2:file:./target/test
spring.datasource.driver-class-name = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password = sa
spring.liquibase.change-log = classpath:/db/changelog/db.changelog-master.yaml
spring.h2.console.enabled = true
spring.h2.console.path = /h2-console
# Keys needed for liquibase maven plugin
url = jdbc:h2:file:./target/test
username = sa
password = sa
如果我遵循这种模式,我最终会在 application.properties 中拥有几个名称稍有不同但值相同的键,这种解决方案显然非常丑陋且效率低下。
在 Spring Boot 中配置和使用 Liquibase Maven 插件的高效且可维护的方法是什么?
在收到 Amith Kumar 的答复后进行编辑:
environment=JUnit
spring.datasource.url=jdbc:h2:file:./target/glossary-test
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
url=${spring.datasource.url}
changeLogFile=${spring.liquibase.change-log}
username=${spring.datasource.username}
password=${spring.datasource.password}
编辑后出错:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:dropAll (default-cli) on project test: Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (${spring.datasource.url}) -> [Help 1]
【问题讨论】:
标签: java maven spring-boot liquibase