Hello,

Describe the bug Environment: - JDK 11 - Spring Boot: 2.4.2 - Spring Cloud: 2020.0.1

What's happening: - Test 1: keep config server optional with the dev profile, by overriding property spring.config.import, and run application with dev profile.

# src/main/resources/config/application.yml
spring.config.import: configserver:http://...

# src/main/resources/config/application-dev.yml
spring.config.import: optional:configserver:http://...

✖️Application fails immediately because the config server is not reachable, even if it is declared optional in the profile dev.

  • Test 2: activate config server with the prod profile only, using property spring.config.activate.on-profile, and run application with no profile.
# src/main/resources/config/application.yml
spring.config.import: configserver:http://...
spring.config.activate.on-profile: prod

application.prop: value

✔️Application does not attempt to join the config server ✖️Application fails later because property application.prop is null after bean validation with @NotNull (seems it has not been loaded correctly from the application.yml file).

May be related to other issues created recently in the project, but not sure they are about the exact same problem: #1802, #1801, #1797, #1795 I also tried with Spring Boot 2.4.3 without success.

Thanks in advance for your help. BR

Comment From: spencergibb

I'm afraid that having multiple spring.config.import statements isn't like a normal property. An import in a profile doesn't override the one in main. They all are imported. Something like this seems to work. (where config server has foo.message).

Profile: dev no config server, foo.message=dev-message w/ config server, foo.message=fromconfigserver-message

Profile: prod no config server, fails because it is not optional w/ config server, foo.message=fromconfigserver-message

spring.application.name=foo
# NO spring.config.import here.
#foo.message=default-message

#---
spring.config.activate.on-profile=dev
spring.config.import=optional:configserver:
foo.message=dev-message

#---
spring.config.activate.on-profile=prod
spring.config.import=configserver:
foo.message=prod-message

We're working on the ordering that might allow foo.message in the default profile.

Comment From: v1nc3n4

Hi @spencergibb Thank you for this helpful explanation. I know how to configure properties now. BR

Comment From: spencergibb

I pointed to the above comment to add to our docs.