【问题标题】:Multiple configuration for same environment in spring bootspring boot中同一环境的多个配置
【发布时间】:2020-10-27 13:33:11
【问题描述】:

我目前有一个 Spring Boot 应用程序。

application.yml

application-dev.yml

在 application.yml 我有

spring:
  profiles:
    active: dev

现在我有多个用于开发人员的配置,例如。比如 dev-1、dev-2 和 dev-3

我如何配置它?有什么最好或标准的方法吗?我使用的是 2.3.4 spring boot 版本

【问题讨论】:

  • 拥有多个配置文件(如 dev-1、dev-2 等)怎么样?
  • 是的,这会起作用..但我不知道这是否是标准方式。也许是 spring cloud config
  • 正如@Ikamal 提到的,您可以制定自己的相同环境命名约定。它应该与差异有关。
  • 我知道那个解决方案,但你认为使用spring cloud config更好吗?

标签: spring spring-boot


【解决方案1】:

您可以使用逗号分隔个人资料,例如

spring:
  profiles:
    active: dev, dev-1

但如果你想添加特定属性而不是覆盖它们,如 The spring.profiles.active property follows the same ordering rules as other properties, the highest PropertySource will win ,你可以使用 include

spring:
  profiles:
    active: dev
    include:
      - dev-1

更多信息,请参阅documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-07
    • 2019-08-03
    • 2018-07-31
    • 2018-10-26
    • 1970-01-01
    • 2018-02-26
    • 2019-01-10
    • 1970-01-01
    相关资源
    最近更新 更多