5

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
  • 355
  • 2
  • 6
  • 13

1 Answers1

6

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.

Community
  • 1
  • 1
Andonaeus
  • 872
  • 1
  • 5
  • 21
  • 2
    i've already tried it and added again, but nothing is changed, i've still had this problem – slippery May 06 '16 at 14:58
  • 2
    try moving the application.yml configuration to bootstrap.yml – Andonaeus May 06 '16 at 15:02
  • 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 – slippery May 06 '16 at 15:09
  • 1
    Bootstrap.yml is loaded before application.yml . Here is another SO answer that is actually provided by someone who asked the Spring Cloud creators: http://stackoverflow.com/questions/32997352/what-is-the-diference-between-putting-a-property-on-application-yml-or-bootstrap – Andonaeus May 06 '16 at 15:11
  • 1
    No problem. Since my answer worked for you, would you mind accepting it? – Andonaeus May 06 '16 at 15:22
  • @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. – JayC Apr 04 '17 at 20:42