spring-boot配置文件的调查研究

关于spring-boot的配置文件的调查研究如下:


  1. 在单纯的spring-boot工程中,只有application.properties/yml配置文件


  2. 在spring-boot工程中加入了spring-cloud-config的相关依赖,那么bootstrap和application配置文件才会同时生效


  3. *.properties 与 *.yml 扩展名之间的配置文件,只不过是书写的格式不同:一个普通的KV方式,一个是json的超集方式
    *.properties 优先级>*.yml (spring-boot 1.5.10version测试)

  4. 如果在spring-boot工程中加入了spring-cloud-config的相关依赖,那么就有四种类型的配置文件,按照优先级顺序:
    remote-config-server(配置中心配置) > cmd(命令行)/OS properties(操作系统属性) > application > bootstrap


  5. 如果在这四类配置中,拥有了相同的key,那么会按照上述优先级进行属性值设置(只会设置一次)


  6. 特例:spring.profiles.active的属性值解析的优先级,会发生变化!!!
    优先级是:cmd(命令行)/OS properties(操作系统属性)> bootstrap > application

    如果在 "cmd(命令行)/OS properties(操作系统属性)> bootstrap > application" 配置了 spring.profiles.active 
                    remote-config-server(配置中心配置)  的 spring.profiles.active 值会生效,但是行为(The following profiles are active)不会生效
    如果没在 "cmd(命令行)/OS properties(操作系统属性)> bootstrap > application"配置了 spring.profiles.active 
                    remote-config-server(配置中心配置)   spring.profiles.active 值和行为才有效



扩展阅读,spring-cloud-config server的一些特殊设置(in org.springframework.cloud.bootstrap.config.PropertySourceBootstrapProperties):


Overriding the Values of Remote Properties

The property sources that are added to you application by the bootstrap context are often "remote" (e.g. from a Config Server), and by default they cannot be overridden locally, except on the command line. If you want to allow your applications to override the remote properties with their own System properties or config files, the remote property source has to grant it permission by setting spring.cloud.config.allowOverride=true (it doesn’t work to set this locally). Once that flag is set there are some finer grained settings to control the location of the remote properties in relation to System properties and the application’s local configuration: spring.cloud.config.overrideNone=true to override with any local property source, and spring.cloud.config.overrideSystemProperties=false if only System properties and env vars should override the remote settings, but not the local config files.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值