如何在 Cloud Foundry 中更改默认 spring 配置文件 ("cloud")

How to change default spring profil ("cloud") in cloud foundry

我想在 cf push 之后使用名为 my_profile 的自定义配置文件启动我的 spring-boot 应用程序,但该应用程序始终使用默认配置文件启动 cloud 轮廓。如何指定要加载的确切配置文件?

我已经尝试像这样在 manifest.yml 中添加环境变量:

env:
      SPRING_PROFILES_ACTIVE: my_profile 

但是应用程序加载了两个配置文件(cloud & my_profile

您是否有加载自定义配置文件而不集成默认配置文件的解决方案?

这来自 Java buildpack,它是 Spring Auto-reconifguration 支持。

The Spring Auto-reconfiguration Framework adds the cloud profile to any existing Spring profiles such as those defined in the SPRING_PROFILES_ACTIVE environment variable.

https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-spring_auto_reconfiguration.md

要禁用此行为,您可以禁用 Spring Auto-reconfiguration 支持。

将环境变量 JBP_CONFIG_SPRING_AUTO_RECONFIGURATION 设置为 { enabled: false }

例如:

cf set-env my-cool-app JBP_CONFIG_SPRING_AUTO_RECONFIGURATION '{ enabled: false }'

请注意,这也会禁用 cloud.* 属性和自动重写 bean 以配置服务。

https://github.com/cloudfoundry/java-buildpack-auto-reconfiguration#what-is-auto-reconfiguration

您也可以在 manifest.yaml 内添加如下内容:

env:
  SPRING_PROFILES_ACTIVE: my_profile
  JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'