Skip to content

Spring Cloud Config property spring.config.import is ignored if configuration is imported from dependency #33712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
12ozCode opened this issue Jan 6, 2023 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@12ozCode
Copy link

12ozCode commented Jan 6, 2023

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 ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 6, 2023
@wilkinsona
Copy link
Member

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 #24688 is tracking that work.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2023
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 6, 2023
@santbetv
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants