spring.profiles.include property from spring cloud config

泄露秘密 提交于 2019-12-24 07:18:30

问题


I have a spring boot application. 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: prod
  profiles.include:
    - enable_tls
    - enable_mongo_ssl

Configuration class - bean creation according active profiles:

@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. The active profiles is only prod and does not include "enable_tls" and "enable_mongo_ssl", thus at bean creation, the statement:

@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:

 "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?

For info I am using Finchley.SR3 version.

My current workaround solution is to have all properties externalized in Config Server except spring.profiles.include remaining in the application.yml classpath file.


回答1:


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

Just list all your feature flags (Spring profiles) in bootstrap.yaml ((



来源:https://stackoverflow.com/questions/56163411/spring-profiles-include-property-from-spring-cloud-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!