I have many services they should use Spring Cloud Config. To avoid adding same part of config to properties to all service, I've created submodule in project with such config:

spring:
  cloud:
    bus:
      enabled: true
      refresh:
        enabled: true
      env:
        enabled: true
    stream:
      kafka:
        binder:
          brokers: localhost:9092
  config:
    import: "configserver:http://localhost:8089"

Then added this library as dependency to service and imported its config via @Import(CommonCloudConfigConfiguration.class)

But it seems like that cloud config client is initializing too early, so imported config that brings additional properties file via @PropertySource(value = "classpath:cloud-config-properties-dev.yml", factory = YamlPropertySourceFactory.class, ignoreResourceNotFound = true) doesn't have time to populate the PropertySource. And as result I get exception:

15:30:53.556 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set
    at org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor.postProcessEnvironment(ConfigDataMissingEnvironmentPostProcessor.java:82)

Should such case be working ?

Comment From: wilkinsona

No, I'm afraid not. As mentioned in the reference documentation, @PropertySource annotations aren't processed until we begin creating the application context. This is too late for spring.config.import to be found and processed. You'll have to use an EnvironmentPostProcessor registered in spring.factories to add the shared configuration to the environment. We'd like to make this easier and https://github.com/spring-projects/spring-boot/issues/24688 is tracking that work.

Comment From: santbetv

Cuando salga este mensaje de error, adicionar en el pom de bussinessdomain los siguientes startes:

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

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
        <version>3.1.3</version>
    </dependency>

De esta manera compilará y buscará con bootstrap.yml, los elementos que estén en el microservicio de config-server