Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Load application.properties/yml from dependent jar

Tags:

java

spring

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?

like image 924
adi Avatar asked Feb 01 '17 15:02

adi


1 Answers

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

like image 117
alexmagnus Avatar answered Nov 16 '22 19:11

alexmagnus