有没有一种简单的方法可以在部署时隔离 Liquibase 执行的上下文?

Is there a simple way to isolate context for Liquibase execution on deployment?

我正在为将使用 Spring 引导的新服务定义架构。我正在寻找一种方法来配置 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

除了所有 beans 的极端配置文件定义之外,是否有其他方法,或者 运行 在 Spring 引导之外手动使用 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。