简体   繁体   中英

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

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.

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.

All propsitions here works if I wrap my command line to jvmArguments.

./mvnw  -Dspring-boot.run.jvmArguments="-Dspring.config.additional-location=file:./secrets.yml"

Thank you for all your reply

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM