简体   繁体   中英

Override application.yml with environment variable in Spring boot

I need my application should pick value of a key from environment variables instead of application.yml.

  1. If a particular property is available in both environment variables as well as in appliation.yml then it should pick the value which is specified as part of environment variables.

  2. If a particular property is not there in environment variables then it should pick value from application.yml else not.

For your two questions. You can use something like:

spring:
  profiles: ${YOUR_ENV_FOR_PROFILE:YOUR_DEFAULT_PROFILE}

If you set an environment variable(Ex. YOUR_ENV_FOR_PROFILE) then spring use it, otherwise spring use a default value "YOUR_DEFAULT_PROFILE"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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