参考官方文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:

  1. Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
  2. @TestPropertySource annotations on your tests.
  3. properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
  4. Command line arguments.
  5. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
  6. ServletConfig init parameters.
  7. ServletContext init parameters.
  8. JNDI attributes from java:comp/env.
  9. Java System properties (System.getProperties()).
  10. OS environment variables.
  11. RandomValuePropertySource that has properties only in random.*.
  12. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).
  13. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
  14. Application properties outside of your packaged jar (application.properties and YAML variants).
  15. Application properties packaged inside your jar (application.properties and YAML variants).
  16. @PropertySource annotations on your @Configuration classes.
  17. Default properties (specified by setting SpringApplication.setDefaultProperties).

由于SpringCloud config的配置文件属于上面的第14/12,理论上优先级相对java -jar命令行参数来说是要低的,但cloud的配置确默认是:远程覆盖本地(OS/java -jar参数等)overrideSystemProperties = true,需要特别注意。

package org.springframework.cloud.bootstrap.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Properties for Spring Cloud Config bootstrap.
*
* @author Dave Syer
*/
@ConfigurationProperties("spring.cloud.config")
public class PropertySourceBootstrapProperties { /**
* Flag to indicate that the external properties should override system properties.
* Default true.
*/
private boolean overrideSystemProperties = true; /**
* Flag to indicate that {@link #isOverrideSystemProperties()
* systemPropertiesOverride} can be used. Set to false to prevent users from changing
* the default accidentally. Default true.
*/
private boolean allowOverride = true; /**
* Flag to indicate that when {@link #setAllowOverride(boolean) allowOverride} is
* true, external properties should take lowest priority and should not override any
* existing property sources (including local config files). Default false.
*/
private boolean overrideNone = false; public boolean isOverrideNone() {
return this.overrideNone;
} public void setOverrideNone(boolean overrideNone) {
this.overrideNone = overrideNone;
} public boolean isOverrideSystemProperties() {
return this.overrideSystemProperties;
} public void setOverrideSystemProperties(boolean overrideSystemProperties) {
this.overrideSystemProperties = overrideSystemProperties;
} public boolean isAllowOverride() {
return this.allowOverride;
} public void setAllowOverride(boolean allowOverride) {
this.allowOverride = allowOverride;
} }

Springboot属性加载与覆盖优先级与SpringCloud Config Service配置的更多相关文章

  1. SpringBoot配置文件加载位置与优先级

    1. 项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件 –fil ...

  2. SpringBoot——配置文件加载位置及外部配置加载顺序

    声明 本文部分转自:SpringBoot配置文件加载位置与优先级 正文 1. 项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者applic ...

  3. SpringBoot 教程之属性加载详解

    免费Java高级资料需要自己领取,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G.            ...

  4. SpingBoot 属性加载

    属性加载顺序 配置属性加载的顺序 开发者工具 `Devtools` 全局配置参数: 单元测试上的 `@TestPropertySource` 注解指定的参数: 单元测试上的 `@SpringBootT ...

  5. Springboot配置文件加载顺序

    使用Springboot开发的时候遇到了配置的问题,外部config里的配置文件本来没有配置https怎么启动还是https呢,原来开发中测试https在classpath路径的配置文件添加https ...

  6. springboot Properties加载顺序源码分析

    关于properties: 在spring框架中properties为Environment对象重要组成部分, springboot有如下几种种方式注入(优先级从高到低): 1.命令行 java -j ...

  7. Spring Boot的属性加载顺序

        伴随着团队的不断壮大,往往不需要开发人员知道测试或者生产环境的全部配置细节,比如数据库密码,帐号信息等.而是希望由运维或者指定的人员去维护配置信息,那么如果要修改某项配置信息,就不得不去修改项 ...

  8. Springboot默认加载application.yml原理以及扩展

    Springboot默认加载application.yml原理以及扩展 SpringApplication.run(...)默认会加载classpath下的application.yml或applic ...

  9. SpringBoot系列——加载自定义配置文件

    前言 SpringBoot启动时默认加载bootstrap.properties或bootstrap.yml(这两个优先级最高).application.properties或application. ...

随机推荐

  1. Gitlab创建一个项目(三)使用IntelliJ IDEA开发项目

    Gitlab创建一个项目 Gitlab创建一个项目(二)创建新用户以及分配项目 1.登陆到gitlab 2.点击项目名,获取http的URL 3.idea打开,选择git 4.设置项目路径以及本地保存 ...

  2. cpython多进程

    四 同步\异步and阻塞\非阻塞(重点) 同步: #所谓同步,就是在发出一个功能调用时,在没有得到结果之前,该调用就不会返回.按照这个定义,其实绝大多数函数都是同步调用.但是一般而言,我们在说同步.异 ...

  3. c++查询特定字符串位置

    size_t find (const string& str, size_t pos = 0) const noexcept;(摘自c++官网:std::string::find) size_ ...

  4. C# List<T>排序总结

    这里有很多种方法对List进行排序,本文总结了三种方法,但有多种实现. 1.对基础类型排序 方法一: 调用sort方法,如果需要降序,进行反转: List<int> list = new ...

  5. 《逆袭团队》第九次团队作业:Beta冲刺与验收准备

    项目 内容 软件工程 任课教师博客主页链接 作业链接地址 团队作业9:Beta冲刺与团队项目验收 团队名称 逆袭团队 具体目标 (1)掌握软件黑盒测试技术:(2)学会编制软件项目总结PPT.项目验收报 ...

  6. luoguP1120小木棍(POJ - 1011 )

     题意: 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50,个数不超过65. 现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度. 给出每段 ...

  7. MySQL——时间戳和时间的转化

    前言 Mysql中时间戳和时间的转化 时间转时间戳 select unix_timestamp('2019-7-29 14:23:25'); 时间戳转时间 select from_unixtime(1 ...

  8. 【Selenium-WebDriver实战篇】java测试使用HttpClient debug日志关闭

    在上一篇设置完Tess4J之后,引用jar包之前,我的日志体系一直是只出现info级别的,但是引用之后出现很多httpClient的请求. 于是网上调查了下,可以通过代码实现,就在入口程序增加该部分代 ...

  9. 性能:Receiver层面

    创建多个接收器 多个端口启动多个receiver在其他Executor,接收多个端口数据,在吞吐量上提高其性能.代码上: import org.apache.spark.storage.Storage ...

  10. Codechef:Fibonacci Number/FN——求通项+二次剩余+bsgs

    题意 定义 $F_n$ 为 $$F_n = \left\{\begin{matrix}0, n=0\\ 1, n=1 \\F_{n-1} + F_{n-2}, n > 1\end{matrix} ...