Skip to content
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

spring.config.import / spring.config.activate.on-profile properties not working as expected with profiles in 2.4.2 #1807

Closed
v1nc3n4 opened this issue Feb 24, 2021 · 3 comments
Assignees

Comments

@v1nc3n4
Copy link

v1nc3n4 commented Feb 24, 2021

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

@spencergibb
Copy link
Member

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.

@v1nc3n4
Copy link
Author

v1nc3n4 commented Mar 30, 2021

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

@spencergibb
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants