Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot external config with sensitive information not working

I am trying to load an external yml file into my spring boot app On my classpath, I have 3 yml files for dev prod and tls profiles.

What I intend to do is to load an external file with the name "secret.yml" to override the values on the application-{profiles}.yml file.

This "secret.yml" file contains sensetive information. It will be add to gitignore file.

After some tries, I founded that spring not override the values inside the classpath only if I change the name to application-{profiles}.yml and not secret.yml

I tried to add spring.config.name=secret but that not working for me.

./mvnw -Dmaven.test.skip=true -Dspring.config.additional-location=file:./secret.yml -Dspring.config.name=secret.yml

Have you any solution for that issue ?

[UPDATE]

I do export environment variable export secret="secret.yml" and then pass the variable to my command line

./mvnw -Dmaven.test.skip=true -Dspring.config.additional-location=file:./secret -Dspring.config.name=secret

Nothing changed

like image 922
Hamdy Avatar asked Nov 26 '25 04:11

Hamdy


2 Answers

if you pass multiple config file, take care the order, the last one will be override to previous config sequentially.

-Dspring.config.location=classpath:application-1.yaml,classpath:application-2.yaml .. other config

the value of application-2.yaml will be override into application-1.yaml if they have same config.

**That will be merged for different config.

like image 60
Zaw Than oo Avatar answered Nov 27 '25 16:11

Zaw Than oo


Try to use a absolute path as on spring boot documentation:

java -jar app.jar --spring.config.name=application --spring.config.location=file:///Users/home/secret

If you don't know the absolute path you can find it with pwd command.

like image 33
Mihai B. Avatar answered Nov 27 '25 18:11

Mihai B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!