简体   繁体   English

使用命令行参数覆盖 spring-boot 中的 yml 配置

[英]Override yml configuration in spring-boot with command line arguments

I have a spring-boot application that is configured with a yml file.我有一个配置了 yml 文件的 spring-boot 应用程序。 Is it possible to override these properties when executing the jar?执行jar时是否可以覆盖这些属性? For example let say I have the input variable in yml file set to user1 and I want to execute the jar with user2.例如,假设我将 yml 文件中的输入变量设置为 user1,并且我想用 user2 执行 jar。 Is it possible to do something like this?有可能做这样的事情吗?

java -jar --input=user2

To elaborate answer by cLyric , you can do this: 通过cLyric详细解答 ,您可以这样做:

java -jar yourapp.jar --input=user2

Or if you want to provide using json, you can do 或者如果你想使用json提供,你可以这样做

java -jar yourapp.jar --spring.application.json='{"input":"user2"}'

Or if you're in unix/linux, 或者如果你在unix / linux中,

SPRING_APPLICATION_JSON='{"input":"user2"}' java -jar yourapp.jar 

this worked for me这对我有用

java -Dspring.profiles.active=test-environment -jar config-server-0.0.1-SNAPSHOT.jar java -Dspring.profiles.active=测试环境-jar config-server-0.0.1-SNAPSHOT.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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