java - spring.profiles.include 来自 spring 云配置的属性
问题描述
我有一个弹簧启动应用程序。我在 application.yml 中使用spring.profiles.include根据给定的配置文件添加一些活动配置文件,然后我使用这些活动配置文件来创建 bean,如下所示:
应用程序.yml:
spring:
profiles: prod
profiles.include:
- enable_tls
- enable_mongo_ssl
配置类 - 根据活动配置文件创建 bean:
@Configuration
@PropertySource("classpath:/mongo-${mongo.environment}.properties")
public class MongoConfiguration {
@Bean
@Profile("enable_mongo_ssl")
public MongoClientOptions.Builder mongoClientOptionsBuilder() {
return getMongoClientOptionsBuilder();
}
这工作正常。但是,当我删除 application.yml 并通过 Spring Cloud Config 使用外部配置时 - 使用 Git 存储库,这不起作用。活动配置文件只是 prod,不包括“enable_tls”和“enable_mongo_ssl”,因此在创建 bean 时,语句:
@Profile("enable_mongo_ssl")
不再是真的。
当我查询环境控制器时,我可以看到配置文件 enable_tls 和 enable_mongo_ssl:
"profiles": [
"prod"
],
"label": null,
"version": "2ddd208fff7caa48b2ae41d69020325ce61f241e",
"state": null,
"propertySources": [
{
"name": "file:///C://dev/config-repo/config/application-prod.yml",
"source": {
"spring.profiles.include[0]": "enable_tls",
"spring.profiles.include[1]": "enable_mongo_ssl",
"server.ssl.key-store-password": "ENC(xxx)",
}
}
有限制吗?我们可以在外部配置中而不是在本地 application.yml 文件中使用 spring.profiles.include 吗?
有关信息,我正在使用 Finchley.SR3 版本。
我目前的解决方案是在 Config Server 中外部化所有属性,除了 spring.profiles.include 保留在 application.yml 类路径文件中。
解决方案
他们不想从服务器实现递归配置文件检索:
https://github.com/spring-cloud/spring-cloud-config/issues?q=is%3Aissue+spring.profiles.include
只需在 bootstrap.yaml ((
推荐阅读
- sql - 是否可以使用 SubQuery 而不是自联接重写此 CosmosDb SQL 查询?
- django - Django - Factoryboy:使用字符串格式化的 __str__ 调用返回对象
- java - java应用程序作为windows server 2016服务在通过powershell安装时没有启动
- python - 排查 CSV 中的无效行
- kubernetes - 部署 nginx 入口控制器时错误创建资源“configmaps”
- gcc - 逆向工程组装
- php - 如何使用php删除最后一个单词和最后一个字母如果是文本第一个单词的'n'
- android - 使用 WifiManager 连接到 wifi 网络后,移动数据保持启用状态
- java - jaspersoft studio 6.10.0 for java bean 数据源适配器 no class def found 错误
- node.js - 如何按标签向 Imgur API 请求随机图像?