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.additional-location as environment variable does not work correctly #17843

Closed
Fantaztig opened this issue Aug 12, 2019 · 8 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@Fantaztig
Copy link

We have a central yml file containing properties for our databases and would like to generically add those to our spring boot services.
We just upgraded to spring boot 2.1.6
What I attempted was to set SPRING_CONFIG_ADDITIONALLOCATION as system environment variable pointing to the location of the application.yml containing the db properties.
Unfortunately, it wouldn't recognize the file, setting it with SPRING_CONFIG_LOCATION works fine however.
As far as I understood the file in the additional location needs to be named application.yml as long as spring.config.name is not set otherwise. I even tried renaming and formatting it to application.properties.
Is this the way it's supposed to be or did I anything wrong?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 12, 2019
@snicoll
Copy link
Member

snicoll commented Aug 12, 2019

@Fantaztig I am not sure what you've done or where the confusion comes from. The behaviour is described in the documentation. If that doesn't help, please share a small sample (github or project zip) with instructions to let us reproduce that locally.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Aug 12, 2019
@Fantaztig
Copy link
Author

Fantaztig commented Aug 12, 2019

Okay, to clarify my confusion I made a simple demo project
https://github.com/Fantaztig/spring-boot-demo
It takes the message from the property greeting and prints it to stdout.

My expectation would be that I can set a system environment variable via
export SPRING_CONFIG_ADDITIONALLOCATION=file:/var/xy/.
Then I place an application.properties file in that folder, which has greeting defined eg.
greeting=Hello World!.

Now, when I start the application it should print "Hello World!", instead I get
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'greeting' in value "${greeting}"

Edit: FYI, we are running our applications on RHEL 6/7 with jdk 1.8

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 12, 2019
@mbhave
Copy link
Contributor

mbhave commented Aug 12, 2019

Thanks for the sample @Fantaztig. This looks like a bug to me. Instead of using the relaxed rules that we use for property binding, we are relying on Spring Framework's rules for getting a property from the System environment.

While we fix this, you should be able to SPRING_CONFIG_ADDITIONAL_LOCATION.

@mbhave mbhave added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Aug 12, 2019
@mbhave mbhave added this to the 2.1.x milestone Aug 12, 2019
@mbhave mbhave self-assigned this Aug 13, 2019
@mbhave mbhave modified the milestones: 2.1.x, 2.1.8 Aug 13, 2019
@mbhave mbhave closed this as completed in 3515ec1 Aug 13, 2019
@skloessel
Copy link

skloessel commented Nov 28, 2019

Hello,

Is there still a bug in Spring Boot 2.2.1.RELEASE with "spring.config.additional-location"?

Consider that we've application.properties in the classpath with defaults:
Having

--spring.profiles.active=P1,P2,P3 and 
--spring.config.additional-location=/path/to/ .... 

/path/to/application-P1.properties
/path/to/application-P2.properties
/path/to/application-P3.properties

the -profile configurations are not loaded as expected in the order P3,P2,P1 ... or the default values defined in the classpath are not overwritten correctly. (the classpath provides profile based properties files too)

The override seems to work just for profile P3 (... the last listed active profile).
Properties in P2 do not become effective - default values from the classpath are used.

Many thanks.

@wilkinsona
Copy link
Member

@skloessel Your problem doesn't appear to be related to this issue as you're not using an environment variable. If you think you may have found a bug, please open a new issue attaching a small sample project that reproduces the behaviour you have described above.

@virtualdxs
Copy link

Is this valid? I was under the impression that environment variables were not allowed to contain hyphens.

@mbhave
Copy link
Contributor

mbhave commented Apr 20, 2020

@virtualdxs This issue isn't about hyphens in environment variables. It was about the recommended format for environment variables (uppercase separate by _) not working for spring.config.additional-location.

If you were referring to my comment, that was just a workaround till the fix was available. In any case, I might have meant ADDITIONAL_LOCATION as the workaround and I've updated that comment.

If you have any more questions, please ask them on Gitter or StackOverflow.

@Fantaztig
Copy link
Author

I think ADDITIONAL_LOCATION didn‘t work either, however I’m not 100% sure about that.
@virtualdxs hyphens in environment variables are not allowed in Unix Systems afaik. E.g. when you start a process from within another java application it is possible though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

7 participants