简体   繁体   中英

spring.profiles.include property from spring cloud config

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.

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 ((

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM