Springboot属性加载与覆盖优先级与SpringCloud Config Service配置
参考官方文档: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:
- Devtools global settings properties on your home directory (
~/.spring-boot-devtools.propertieswhen devtools is active). @TestPropertySourceannotations on your tests.propertiesattribute on your tests. Available on@SpringBootTestand the test annotations for testing a particular slice of your application.- Command line arguments.
- Properties from
SPRING_APPLICATION_JSON(inline JSON embedded in an environment variable or system property). ServletConfiginit parameters.ServletContextinit parameters.- JNDI attributes from
java:comp/env. - Java System properties (
System.getProperties()). - OS environment variables.
- A
RandomValuePropertySourcethat has properties only inrandom.*. - Profile-specific application properties outside of your packaged jar (
application-{profile}.propertiesand YAML variants). - Profile-specific application properties packaged inside your jar (
application-{profile}.propertiesand YAML variants). - Application properties outside of your packaged jar (
application.propertiesand YAML variants). - Application properties packaged inside your jar (
application.propertiesand YAML variants). @PropertySourceannotations on your@Configurationclasses.- 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配置的更多相关文章
- SpringBoot配置文件加载位置与优先级
1. 项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件 –fil ...
- SpringBoot——配置文件加载位置及外部配置加载顺序
声明 本文部分转自:SpringBoot配置文件加载位置与优先级 正文 1. 项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者applic ...
- SpringBoot 教程之属性加载详解
免费Java高级资料需要自己领取,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G. ...
- SpingBoot 属性加载
属性加载顺序 配置属性加载的顺序 开发者工具 `Devtools` 全局配置参数: 单元测试上的 `@TestPropertySource` 注解指定的参数: 单元测试上的 `@SpringBootT ...
- Springboot配置文件加载顺序
使用Springboot开发的时候遇到了配置的问题,外部config里的配置文件本来没有配置https怎么启动还是https呢,原来开发中测试https在classpath路径的配置文件添加https ...
- springboot Properties加载顺序源码分析
关于properties: 在spring框架中properties为Environment对象重要组成部分, springboot有如下几种种方式注入(优先级从高到低): 1.命令行 java -j ...
- Spring Boot的属性加载顺序
伴随着团队的不断壮大,往往不需要开发人员知道测试或者生产环境的全部配置细节,比如数据库密码,帐号信息等.而是希望由运维或者指定的人员去维护配置信息,那么如果要修改某项配置信息,就不得不去修改项 ...
- Springboot默认加载application.yml原理以及扩展
Springboot默认加载application.yml原理以及扩展 SpringApplication.run(...)默认会加载classpath下的application.yml或applic ...
- SpringBoot系列——加载自定义配置文件
前言 SpringBoot启动时默认加载bootstrap.properties或bootstrap.yml(这两个优先级最高).application.properties或application. ...
随机推荐
- mybatis添加sql打印功能
添加配置文件: mybatis-config.xml <?xml version="1.0" encoding="UTF-8"?> <!DOC ...
- 关于jupyter notebook密码设置
对于一个jupyter编辑器使用的新手,更换浏览器或者Logout后,需要输入密码进行登陆时 按照网上的教程怎么设置都不行,那么自己整理了一个适用于初学者的操作. 1.windows下,打开命令行,重 ...
- Springboot项目中Pom.xml报错
摘要:使用idea,两次在maven上浪费时间,第一次不知道怎么就解决了,第二次记录一下解决办法 参考博客地址: https://blog.csdn.net/u013129944/article/de ...
- OpenStack共享组件-Memcache缓存系统
1. 缓存系统 1.1 静态web页面 1> 在静态Web程序中,客户端使用Web浏览器(IE.FireFox等)经过网络(Network)连接到服务器上,使用HTTP协议发起一个请求(Requ ...
- DP-LIS and LCS
最长上升子串 f[i]=f[I-1]+1(f[I]>f[I-1]) f[I]=1;(f[I]<=f[I-1]) 输出max(f(I)) 最长上升子序列 f[I]=max(f[I],f[j] ...
- 第二次作业之——AchaoCalculator
AchaoCalculator(阿超计算器) GIT地址 我的GitHub GIT用户名 Pastrain 学号后五位 62213 博客地址 我的博客地址 作业链接 作业内容 Part.1 配置VS中 ...
- python爬虫中的ip代理设置
设置ip代理是爬虫必不可少的技巧: 查看本机ip地址:打开百度,输入“ip地址”,可以看到本机的IP地址: 本文使用的是goubanjia.com里面的免费ip: 使用时注意要注意传输协议是http还 ...
- LOJ#2343. 「JOI 2016 Final」集邮比赛 2
题目地址 https://loj.ac/problem/2343 题解 首先处理出\(f[i]\)表示以当前位置开头(J,O,I)的合法方案数.这个显然可以\(O(n)\)处理出来.然后考虑在每个位置 ...
- 项目Alpha冲刺 10
作业描述 课程: 软件工程1916|W(福州大学) 作业要求: 项目Alpha冲刺(团队) 团队名称: 火鸡堂 作业目标: 介绍第10天冲刺的项目进展.问题困难和心得体会 1.团队信息 队名:火鸡堂 ...
- Centos7 Mysql主从双机热备的实战记录
操作系统:centos7 服务器:主:172.19.242.69 从:172.19.242.70 1. 服务器 由于Mysql不同版本之间的(二进制日志)binlog格式可能会不太一样,因此最好的 ...