[英]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.我正在尝试将外部 yml 文件加载到我的 Spring Boot 应用程序中 在我的类路径上,我有 3 个 yml 文件用于 dev prod 和 tls 配置文件。
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.我打算做的是加载一个名为“secret.yml”的外部文件来覆盖 application-{profiles}.yml 文件中的值。
This "secret.yml" file contains sensetive information.这个“secret.yml”文件包含有意义的信息。 It will be add to gitignore file.它将被添加到 gitignore 文件中。
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经过一些尝试,我发现只有当我将名称更改为 application-{profiles}.yml 而不是 secret.yml 时,spring 才不会覆盖类路径中的值
I tried to add spring.config.name=secret
but that not working for me.我试图添加spring.config.name=secret
但这对我不起作用。
./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我导出环境变量export secret="secret.yml"
然后将变量传递给我的命令行
./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.如果您传递多个配置文件,请注意order
,最后一个将按顺序覆盖到先前的配置。
-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.如果它们具有相同的配置, application-2.yaml
的值将被覆盖到application-1.yaml
。
**That will be merged for different config. **这将针对不同的配置进行合并。
Try to use a absolute path as on spring boot documentation :尝试使用 spring boot文档中的绝对路径:
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.如果您不知道绝对路径,可以使用pwd
命令找到它。
All propsitions here works if I wrap my command line to jvmArguments.如果我将命令行包装到 jvmArguments,这里的所有道具都可以工作。
./mvnw -Dspring-boot.run.jvmArguments="-Dspring.config.additional-location=file:./secrets.yml"
Thank you for all your reply谢谢大家的回复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.