Java application.yml 是否支持环境变量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23027315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does application.yml support environment variables?
提问by Marcel Overdijk
I tried using env variables in my application.yml configration like:
我尝试在 application.yml 配置中使用 env 变量,例如:
spring:
main:
show_banner: false
---
spring:
profiles: production
server:
address: $OPENSHIFT_DIY_IP
port: $OPENSHIFT_DIY_PORT
but the env variables are not resolved. Do I have to provide a different notation?
但 env 变量没有解析。我必须提供不同的符号吗?
In Rails you can e.g. use <%= ENV['FOOVAR'] %>
在 Rails 中,你可以使用 <%= ENV['FOOVAR'] %>
The only alternative is to run the app like:
唯一的选择是运行应用程序,如:
java -jar my.jar --server.address=$OPENSHIFT_DIY_IP --server.port=$OPENSHIFT_DIY_PORT
采纳答案by Dave Syer
回答by Alex Efimov
You even can add default value, if environment variable not provided:
如果未提供环境变量,您甚至可以添加默认值:
logging:
level:
root: ${LOGGING_LEVEL_ROOT:info}