spring-boot - 有没有一种简单的方法来隔离部署时 Liquibase 执行的上下文?
问题描述
我正在为将使用 Spring Boot 的新服务定义架构。我正在寻找一种方法来配置 Liquibase 部署以仅在某个配置文件处于活动状态时执行。如果可能,我还想禁用所有其他组件,以避免在数据库部署完成之前来自服务逻辑的操作。
我已经成功启动了我的服务,并且看到我的变更集执行了。除了对所有组件进行极端配置文件操作之外,我不确定其他方法可以使我的 Liquibase 配置文件成为独立执行,从而避免在应用程序上下文中实例化组件。
这是我的配置:
spring:
application:
name: liquibase-spring-postgres-example
liquibase:
enabled: false
---
spring:
profiles: dev
datasource:
username: ${service_user}
password: ${DATASOURCE_DB_PASS}
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
url: jdbc:postgresql://{db}:{port}/schema
---
spring:
profiles: liquibase
datasource:
## provided to get spring boot to start up
url: jdbc:postgresql://{db}:{port}/schema
liquibase:
user: ${liquibase_user}
password: ${LIQUIBASE_DB_PASS}
contexts: release
enabled: true
我已经尝试在我在这里找到的评论的帮助下成功禁用嵌入式码头服务器之类的东西:
spring:
...
main:
web-application-type: none
除了所有 bean 的极端配置文件定义之外,是否还有其他方法,或者在 Spring Boot 之外手动运行 Liquibase 以实现这一点?
解决方案
要针对 spring-boot jar 文件执行脚本,这样的内容应该可以帮助您:
java -cp /path/to/spring-boot-fat.jar \
-Dloader.system=true \
-Dloader.main=liquibase.integration.commandline.Main \
org.springframework.boot.loader.PropertiesLauncher \
--changeLogFile=db/changelog/db-changelog-master.xml \
--driver=org.h2.Driver \
--url="jdbc:h2:~/h2db/liquibase-test;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE" \
--password=sa \
--username=sa \
updateSQL
编辑:这是针对 spring-boot 1.5.x 测试的,但我想它也应该针对 2.x 工作。
推荐阅读
- javascript - Razorpay 集成。问题:请提供您的 api 密钥以进行身份验证
- ios - UserDefaults UIButton 状态有时加载不正确
- xcode - Xcode 11 无法创建 Mac 应用分发证书
- ios - 在 ViewController 中设置 TableView 和 collectionView
- c# - XML 声明包含换行符而不是双引号 - 在 C# 中创建 xml 文档时
- python - Apache spark中两个简单rdd的协方差
- angular - 打字稿继承中的覆盖函数
- swift - 获取某些对象的关系计数(核心数据)
- google-apps-script - 使用谷歌应用脚本从谷歌文档中提取文本
- android - 如何从具有内核读/写功能的 ARM64 程序中获取 swapper_pg_dir 地址?