Settings in application.yml for spring.cloud.config aren't used when app is executing

14,229

You need to add the following to your application.yml file:

spring:
    cloud:
        config:
            enabled: true

Per comment chain, you also need to add the properties to bootstrap.yml instead of application.yml . The reason is that the former is loaded before the latter in the spring startup cycle. Here is another SO post answered by user Michael Isvy explaining why, and copied below for posterity: What is the diference between putting a property on application.yml or bootstrap.yml in spring boot?

I have just asked the Spring Cloud guys and thought I should share the info I have here.

bootstrap.yml is loaded before application.yml.

It is typically used for the following:

  • when using Spring Cloud Config Server, you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml
  • some encryption/decryption information

Technically, bootstrap.yml is loaded by a parent Spring ApplicationContext. That parent ApplicationContext is loaded before the one that uses application.yml.

Share:
14,229
slippery
Author by

slippery

Updated on June 04, 2022

Comments

  • slippery
    slippery almost 2 years

    I have a problem with spring cloud: my settings in application.yml for spring.cloud.config aren't used when app is executing. let me put more detail here. I'd like to my services could get settings from a remote ConfigServer. I've created the ConfigServer as a spring boot app with annotation @EnableConfigServer. After that i've created client app with next config file:

        application:
          name: mw
        cloud:
          config:
            enabled: true
            uri: http://172.17.42.1:8888
            fail-fast: true
    

    main class:

        @EnableEurekaClient
        @SpringBootApplication
        public class MwApplication
    

    and extra configuration into app:

        @Configuration
        @EnableJpaRepositories(basePackages = {"com.sample.repository"})
        @EnableTransactionManagement
        @EnableScheduling
        public class AppConfiguration
    

    also i have next dependencies:

        spring-cloud-starter-eureka
        spring-cloud-config-client
        spring-boot-configuration-processor
        spring-boot-starter-data-jpa
    

    When i execute my client app, i've got this message: ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/mw/default"

    The app try to get data from default uri(localhost) instead of to use uri from my setting. I've looked at app in debug mode and saw org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration was creating ConfigClientProperties with default property and my settings from application.yml weren't used.

    What am i doing wrong? thanks.

  • slippery
    slippery almost 8 years
    i've already tried it and added again, but nothing is changed, i've still had this problem
  • Andonaeus
    Andonaeus almost 8 years
    try moving the application.yml configuration to bootstrap.yml
  • slippery
    slippery almost 8 years
    now it works, thank you! Could you say why it didn't work with application.yml? i didn't create application.yml by myself. it was created by spring constructor
  • Andonaeus
    Andonaeus almost 8 years
    Bootstrap.yml is loaded before application.yml . Here is another SO answer that is actually provided by someone who asked the Spring Cloud creators: stackoverflow.com/questions/32997352/…
  • Andonaeus
    Andonaeus almost 8 years
    No problem. Since my answer worked for you, would you mind accepting it?
  • JayC
    JayC about 7 years
    @slippery So you are saying your application worked when you moved the app.yml configs to bootstrap.yml? I did the same but my application does not run.