5
votes

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; .... }

base-application.yml

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?

2

2 Answers

4
votes

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

0
votes

if property files are in META-INF directory of jar, you can load of them as follows: "classpath*:/META-INF/*.properties"