Spring Boot 中配置文件bootstrap 和 application的区别

1、spring boot 有以下两种配置文件:

   * bootstrap(.yml 或者 properties)

   * application(.yml 或者 properties)

2、bootstrap 和 application 的区别:

  在spring boot的官方文档中没有找到,而在spring cloud 的官方文档中找到了bootstrap和application配置的区别。

 http://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#thebootstrapapplicationcontext

 

        和application 配置文件相比,bootstrap 配置文件具有以下几个特性:

        ①、bootstrap 由父ApplicationContext加载,比application优先加载;

        ②、bootstrap里面的属性不能被覆盖;

3、bootstrap 和application 的应用场景:

application:

         主要用于spring boot 项目的自动化配置;

bootstrap:

         a、使用spring Cloud config 配置中心时,这时需要在bootstrap 配置文件中添加连接到配置中心的配置属性来加载外部配置中心的配置信息;

         b、一些固定的不能被覆盖的配置;

         c、一些加密/解密的场景;

Spring Boot 中配置文件bootstrap 和 application的区别