0

I am facing an issue while trying to start Config Client with the below dependency:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>

The placeholder i am trying to get is the Environment variable which will help me pick up the files from config server. E.g config-client-{ENVIRONMENT}.properties

Exception: java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ENVIRONMENT' in value "${ENVIRONMENT}"

4
  • Can you try the below instead? -Dspring.profiles.active=<ENVIRONMENT>. Additionally, you can have the below as well in application.yml file (please format the content) "spring: profiles: active: <ENV> include: application-${spring.profiles.active}.yml"
    – Govind
    Jun 15, 2020 at 16:56
  • where does ENVIRONMENT get set? Jun 15, 2020 at 17:03
  • you are not providing enough info. Jun 15, 2020 at 17:24
  • Environment gets the value injected from the Jenkins Pipeline. Jun 15, 2020 at 18:51

1 Answer 1

1

In Spring Boot ${ENVIRONMENT} does not come out of box.

You have two options.

  1. Set ENVIRONMENT= in all application.yml files. So you can get it at run time.

  2. Fetch the file config-client-${spring.profiles.active}.properties so it will get the property file as per the spring profile.

1
  • Yes i followed the approach you mentioned above and it works fine. Thank you! Jun 15, 2020 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.