Spring Boot Profile 不覆盖属性

问题描述 投票:0回答:1

我有一个使用两个 yml 配置文件的 Spring Boot 应用程序 3.1.3

application.yml
application-prod.yml

问题是,当我使用 prod 配置文件启动应用程序时,它不会使用此属性覆盖此 application.yml 属性。

application properties
    ---
        spring:
          profiles:
            active: prod
          cloud.config:
            label: main
            uri: https://config-server-main

它继续使用这个application.yml属性

  cloud.config:
    label: qa
    uri: https://config-server-qa

正确的覆盖方法是什么?

java spring-boot
1个回答
0
投票

与 Spring Boot 应用程序相比,Spring Cloud 应用程序具有引导上下文,它是应用程序上下文的父级。虽然它们共享相同的环境,但它们对于定位外部配置文件有不同的约定。

引导上下文正在搜索 bootstrap.properties 或 bootstrap.yaml 文件,而应用程序上下文正在搜索 application.properties 或 application.yaml 文件。

参见:https://www.baeldung.com/spring-cloud-bootstrapping

© www.soinside.com 2019 - 2024. All rights reserved.