Spring Cloud - bootstrap.yml vs application.yml

When using Spring Cloud, the 'real' configuration data is usually loaded from a server. In order to get the URL (and other connection configuration, such as passwords, etc.), you need an earlier or "bootstrap" configuration. Thus, you put the config server attributes in the bootstrap.yml, which is used to load the real configuration data (which generally overrides what's in an application.yml [if present]).

bootstrap.yml is loaded before application.yml.

It is typically used for the following:

  • when using Spring Cloud Config Server, you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml
  • some encryption/decryption information

Technically, bootstrap.yml is loaded by a parent Spring ApplicationContext. That parent ApplicationContext is loaded before the one that uses application.yml.

A Spring Cloud application operates by creating a "bootstrap" context, which is a parent context for the main application. Out of the box it is responsible for loading configuration properties from the external sources, and also decrypting properties in the local external configuration files.

Spring Cloud 应用程序通过创建“bootstrap”上下文来运行,该上下文是主应用程序的父上下文。它负责从外部源加载配置属性,并解密本地外部配置文件中的属性。

使用 Spring Cloud 时,“真实”配置数据通常从服务器加载。为了获取 URL(以及其他连接配置,例如密码等),您需要一个早期或“bootstrap”配置。
因此,您将配置服务器属性放在 bootstrap.yml 中,该文件用于加载真实配置数据(通常会覆盖 application.yml 中的内容 [如果存在])。

bootstrap.yml 在 application.yml 之前加载。

它通常用于以下用途:

  • 使用 Spring Cloud Config Server 时,应在 bootstrap.yml 中指定 spring.application.name 和 spring.cloud.config.server.git.uri
  • 一些加密/解密信息

从技术上讲,bootstrap.yml 由父 Spring ApplicationContext 加载。该父 ApplicationContext 在使用 application.yml 的 ApplicationContext 之前加载。

Ref

END

posted @ 2025-01-09 11:54  炎黄子孙,龙的传人  阅读(50)  评论(0)    收藏  举报