[英]spring.profiles.include property from spring cloud config
I have a spring boot application. 我有一个Spring Boot应用程序。 I am using spring.profiles.include in application.yml to add some active profiles according to a given profile, then I am using those active profiles for bean creation as below:
我正在使用application.yml中的spring.profiles.include根据给定的配置文件添加一些活动配置文件,然后将这些活动配置文件用于Bean创建,如下所示:
application.yml: application.yml:
spring:
profiles: prod
profiles.include:
- enable_tls
- enable_mongo_ssl
Configuration class - bean creation according active profiles: 配置类-根据活动概要文件创建Bean:
@Configuration
@PropertySource("classpath:/mongo-${mongo.environment}.properties")
public class MongoConfiguration {
@Bean
@Profile("enable_mongo_ssl")
public MongoClientOptions.Builder mongoClientOptionsBuilder() {
return getMongoClientOptionsBuilder();
}
This works fine. 这很好。 However when I remove application.yml and use external config through Spring Cloud Config - with Git repository, this does not work.
但是,当我删除application.yml并通过Spring Cloud Config-Git存储库使用外部配置时,这不起作用。 The active profiles is only prod and does not include "enable_tls" and "enable_mongo_ssl", thus at bean creation, the statement:
活动概要文件仅是prod,不包含“ enable_tls”和“ enable_mongo_ssl”,因此在创建Bean时,以下语句:
@Profile("enable_mongo_ssl")
is no longer true. 不再是真的。
When I query the environment controller, I can see the profiles enable_tls and 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)",
}
}
Is there a limitation? 有限制吗? Can we use spring.profiles.include in an external configuration and not in a local application.yml file?
我们可以在外部配置中而不是在本地application.yml文件中使用spring.profiles.include吗?
For info I am using Finchley.SR3 version. 有关信息,我正在使用Finchley.SR3版本。
My current workaround solution is to have all properties externalized in Config Server except spring.profiles.include remaining in the application.yml classpath file. 我当前的解决方法是在Config Server中外部化所有属性,但spring.profiles.include保留在application.yml类路径文件中。
They don't want to implement recursive profile retrieval from server: 他们不想从服务器实现递归配置文件检索:
https://github.com/spring-cloud/spring-cloud-config/issues?q=is%3Aissue+spring.profiles.include https://github.com/spring-cloud/spring-cloud-config/issues?q=is%3Aissue+spring.profiles.include
Just list all your feature flags (Spring profiles) in bootstrap.yaml (( 只需在bootstrap.yaml中列出所有功能标志(Spring配置文件)((
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.