I have a Spring Boot application where I would like to inject values into a @ConfigurationProperties bean in a specific order.
For example,
@ConfigurationProperties("myproperties")
class MyProperties {
private String property1;
....
}
myproperties:
property1: some-value
The above class and properties file is in a jar file. In the mail application of my Spring Boot app (which has the above jar as dependency) I used @PropertySource(value = { "application.yml", "base-application.yml"})
but got null
values in MyProperties
.
I tried
@PropertySources({
@PropertySource("classpath:application.yml"),
@PropertySource("classpath*:base-application.yml")
})
as well, but that didn't work either.
If I add the myproperties.property1 value in application.yml then it works fine. Is it possible to inject property values from a property file which is inside of another jar? If so, what am I doing wrong here?
YAML files can’t be loaded via the @PropertySource annotation. So in the case that you need to load values that way, you need to use a properties file. Check the docs here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With