application.yml 是否支持环境变量?

2022-01-14 00:00:00 yaml spring java spring-boot

我尝试在 application.yml 配置中使用环境变量,例如:

I tried using env variables in my application.yml configration like:

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?

在 Rails 中,您可以例如使用 <%= ENV['FOOVAR'] %>

In Rails you can e.g. use <%= 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

推荐答案

试试 ${OPENSHIFT_DIY_PORT}(通常的 Spring 占位符符号).请参阅此处了解文档.

Try ${OPENSHIFT_DIY_PORT} (the usual Spring placeholder notation). See here for docs.

相关文章