如何更改云代工厂中的默认弹簧配置文件(“云”)

mar*_*rbi 7 java cloud-foundry spring-profiles spring-boot

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

我已经尝试在 manifest.yml 中添加环境变量,如下所示:

env:
      SPRING_PROFILES_ACTIVE: my_profile 
Run Code Online (Sandbox Code Playgroud)

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

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

Dan*_*usa 9

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

Spring Auto-reconfiguration Framework 将云配置文件添加到任何现有的 Spring 配置文件中,例如在 SPRING_PROFILES_ACTIVE 环境变量中定义的配置文件。

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

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

将 env 变量设置JBP_CONFIG_SPRING_AUTO_RECONFIGURATION{ enabled: false }.

前任:

cf set-env my-cool-app JBP_CONFIG_SPRING_AUTO_RECONFIGURATION '{ enabled: false }'
Run Code Online (Sandbox Code Playgroud)

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

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