spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系

时间:2022-07-29 23:19:03

最近在启用springcloud配置中心server的东西,在整理属性资源的时候,突然发现:用了这么久的springboot,为什么会配置两个属性文件同时存在(application.yml/properties,bootstrap.yml/properties).

下面的解释,我认为是最通俗易懂的:

spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系

我的理解来讲,其实就是说:1.加载顺序的先后,bootstrap会先加载,在结合configserver一起使用时,bootstrap属性文件更适合做一些引导下文的配置,比如:

spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系
# 默认配置
spring:
application:
name: demo
cloud:
config: #配置文件获取
uri: http://localhost:8040
label: management
name: application-demo
spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系

2.在结合configserver使用时,bootstrap更多的是配置一些不经常变化甚至不变化的属性。application属性文件可更灵活的配置一些属性. (个人拙见,欢迎拍砖)

spring cloud 配置文件application.yml和bootstrap.yml 的定位,区别和联系

官网文档地址:https://cloud.spring.io/spring-cloud-static/Dalston.SR5/single/spring-cloud.html#_the_bootstrap_application_context

https://www.cnblogs.com/ANCAN-RAY/p/8795448.html

同一个项目若同时存在application.yml和bootstrap.yml ,bootstrap.yml先加载,后加载application.yml,若存在同名属性会覆盖之前的。