Spring Cloud 官方文档:https://cloud.spring.io/spring-cloud-static/spring-cloud.html
一个Spring Cloud的操作是通过创建“bootstrap”context开始的,它是main application最上层的parent context。开箱机用,它负责载入来自于外部的配置信息(properties),同时在本地解码外部配置文件的properties。所有Spring应用程序都是由2个Context共享来自外部properties的环境Environment。 Bootstrap properties在被加载时具有最高的优先权,所以默认情况下bootstrap properties不会被本地配置覆盖。
bootstrap context 使用不同的方式定位外部配置信息,而不是像main application context那样,所以你可以使用bootstrap.yml 代替 application.yml or application.properties, 最好将外部配置交给bootstrap,并与main context分开。
例如: bootstrap.yml
spring:
application:
name: foo
cloud:
config:
uri: ${SPRING_CONFIG_URI:http://localhost:8888}如果你的application在server端有任何特殊的配置,最好是将spring.application.name设置到bootstrap.yml内,因为bootstrap.yml 不会被本地配置所覆盖。你也完全可以通过设置系统属性(system properties)spring.cloud.bootstrap.enabled=false, 来禁用bootstrap process。
本文介绍SpringCloud中Bootstrap的使用方式及重要性。Bootstrap是启动SpringCloud应用的基础上下文,负责加载外部配置信息并确保其优先级高于本地配置。文中详细解释了如何利用bootstrap.yml文件进行配置,以及如何通过系统属性控制其启用或禁用。
7166

被折叠的 条评论
为什么被折叠?



