在 Spring Boot 中,the documentation似乎鼓励在应用程序启动时运行迁移。
这很好,但有时应用程序启动可能会有副作用/依赖性,我不想为此烦恼 - 我只想自己运行迁移。想想只设置一个本地开发数据库,在其中四处查看,甚至不运行应用程序。
相比之下,在 Dropwizard 中,单独运行迁移 is straightforward为应用程序内置参数,就像这样
java -jar hello-world.jar db migrate helloworld.yml
Spring Boot 有什么等价物吗?或者我只需要下拉并直接运行 liquibase 吗?
我对直接回答很感兴趣,但也有兴趣看看我是否误解了更高层次的东西——比如这种在启动时运行的方法可能由于某些我没有的原因通常“更好”尚未发现,因此 Spring Boot 鼓励您仅以这种方式作为设计选择。
最佳答案
您可以使用不同的 Spring 配置文件:例如,使用名为“init”的配置文件,它将激活“liquibase”配置文件。
application.yml:(默认禁用 Liquibase)
spring:
liquibase:
enabled: false
application-init.yml:(不运行web容器,所以spring启动后会自动关闭)
spring:
profiles:
include: liquibase
main:
web-application-type: none
spring-liquibase.yml:(启用 liquibase)
spring:
liquibase:
enabled: true
change-log: classpath:/db/changelog/changelog.xml
此设置允许您将 Liquibase 作为初始容器运行 (spring.profiles.active=init),但如果您愿意,您仍然可以将 Liquibase 作为您的网络应用程序的一部分运行 (spring.profiles.active=liquibase) .
关于java - Spring 启动 : run liquibase migrations without starting app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49532668/