简体   繁体   English

在 Spring 引导中使用环境变量覆盖 application.yml

[英]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.我需要我的应用程序应该从环境变量而不是 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.如果特定属性在环境变量和appliation.yml中都可用,那么它应该选择指定为环境变量一部分的值。

  2. If a particular property is not there in environment variables then it should pick value from application.yml else not.如果环境变量中没有特定属性,那么它应该从application.yml中选择值,否则不。

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"如果设置环境变量(例如 YOUR_ENV_FOR_PROFILE),则 spring 使用它,否则 spring 使用默认值“YOUR_DEFAULT_PROFILE”

暂无
暂无

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

相关问题 spring 启动应用程序.yml 中的环境变量 - Environment variable in spring boot application.yml 在spring.boot中覆盖application.yml文件中的默认值 - override default values in application.yml file spring boot 如何使用 docker run 命令为 Spring Boot 应用程序覆盖 application.yml 中的 spring 属性? - How can you override a spring property in application.yml for a Spring Boot application using the docker run command? Spring Boot application.yml 和 @Value 不起作用 - Spring Boot application.yml and @Value is not working Spring Boot - 如何通过实现 BeforeAllCallback 的自定义扩展类设置或覆盖 application.yml 中定义的属性? - Spring Boot - How to set or override properties defined in application.yml via a custom extension class that implements BeforeAllCallback? docker 环境中的 Spring Boot 外部配置:application.yml 不存在 - Spring boot external config in a docker environment: application.yml does not exist Spring Boot App 无法识别 application.yml 文件中的环境变量 - Spring Boot App does not recognize environment variables in application.yml file 如何使用Spring Boot从application.yml读取变量并在Kotlin测试中使用它 - How to read variable from application.yml with spring boot and use it in kotlin test Java Spring 引导不会从 application.yml 中获取变量 - Java Spring Boot won't pick up variable from application.yml Spring 引导:配置未正确加载我的密码变量来自 application.yml - Spring Boot: configuration does not load correctly my password variable from application.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM