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

标签 java spring-boot cloud-foundry spring-profiles

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

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

env:
      SPRING_PROFILES_ACTIVE: my_profile 

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

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

最佳答案

这来自 Java 构建包和 Spring 自动重新配置支持。

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 自动重新配置支持。

将环境变量 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

关于java - 如何在 Cloud Foundry 中更改默认 Spring 配置文件 ("cloud"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56737584/

相关文章:

docker - 如何从 Cloud Foundry 上的私有(private)存储库部署 Docker 镜像?

java - 为什么在java中入队时必须使用(rear+1)%capacity?

java - 如何使用realm.io(Java/Android)递归删除记录?

java - 更新数据库中的用户权限 Spring boot OAuth 2.0

spring-mvc - Spring Boot - java.lang.ClassNotFoundException : org. springframework.context.ApplicationContextInitializer

security - 保护 Cloud Foundry 环境变量中的服务参数

java - 无法使用 javac 和 lombok 在控制台中编译 .h 文件。错误 : package lombok does not exist

java - 添加所有依赖项,但 NoClassDefFoundError com/intellij/uiDesigner/core/GridLayoutManager

java - 仅使用 Spring Boot Data JPA/Java 8 Instant 查询日期?

java - Pivotal Cloud Foundry 上的 Spring JPA 如何知道如何连接到绑定(bind)的 MySQL 实例?