在 Spring Cloud 中,可以使用 'bootstrap.yml' 文件来覆盖 'application.yml' 中的参数。'bootstrap.yml' 文件被用于在应用程序启动时加载,用于配置 Spring Cloud 的一些基本属性,例如连接到配置服务器、配置加密等。而 'application.yml' 则用于应用程序的业务配置。

'bootstrap.yml' 中的属性将覆盖 'application.yml' 中相同键的值。这样可以确保在应用程序启动时,配置服务器中的配置能够优先于本地的配置被加载。

以下是一个示例:

bootstrap.yml:

spring:
  cloud:
    config:
      uri: http://config-server:8888

application.yml:

spring:
  application:
    name: my-app

在这个示例中,'bootstrap.yml' 中的 'spring.cloud.config.uri' 属性将会覆盖 'application.yml' 中的相同属性。这样,应用程序会连接到 'http://config-server:8888' 来获取配置。

需要注意的是,'bootstrap.yml' 只会在应用程序启动时加载一次,而 'application.yml' 则会在应用程序的整个生命周期中都有效。因此,如果需要动态更新配置,应该将需要动态更新的配置放在 'application.yml' 中。


原文地址: https://www.cveoy.top/t/topic/NgB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录