Does application.yml support environment variables

2019-03-09 06:41发布

问题:

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?

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

回答1:

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



回答2:

You even can add default value, if environment variable not provided:

logging:
  level:
    root: ${LOGGING_LEVEL_ROOT:info}