SpringBoot:SpringBoot原理

SpringBoot高级

SpringBoot配置

配置文件优先级

按照yaml>yml>properties的顺序加载

存在相同配置项,后加载的会覆盖先加载的

加载顺序越靠后,优先级越高

SpringBoot存在其他的多种方式进行配置,如下所示,越靠下优先级越高

1. Default properties (specified by setting SpringApplication.setDefaultProperties).
2. @PropertySource annotations on your @Configuration classes. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins.
3. Config data (such as application.properties files). (上述配置文件的方式)
4. A RandomValuePropertySource that has properties only in random.*.
5. OS environment variables. (系统环境变量方式)
6. Java System properties (System.getProperties()). (java系统参数方式)
7. JNDI attributes from java:comp/env.
8. ServletContext init parameters.
9. ServletConfig init parameters.
10. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
11. Command line arguments. (命令行参数方式)
12. properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
13. @DynamicPropertySource annotations in your tests.
14. @TestPropertySource annotations on your tests.
15. Devtools global settings properties in the $HOME/.config/spring-boot directory when devtools is active.
系统环境变量方式配置

系统环境变量:将一些配置在系统中设置成全局的环境变量

在run configurations中进行配置
请添加图片描述

配置规则

配置项目的

.

使用

_

替换

删除所有的

-

字母全部转为大写

java系统参数方式

(System.getProperties())

在run configurations中进行配置

请添加图片描述

指在运行时,通过

-Dkey=value

进行参数指定

eg:java -Dserver.port=8085 -jar xxxx.jar(命令行)-DServer.port=8085(idea中)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值