spring boot 配置加载顺序

由官网的文档得知

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config

  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()).
  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.

从第3步开始,加载 properties 文件中的配置,接下来第5步加载操作系统环境变量,第6步加载系统属性,第11步加载命令行参数。

如果同一个参数在前面声明了,后面也声明了同样的参数,后面的会覆盖前面的,即以后面的为准。

It is recommended to stick with one format for your entire application. If you have configuration files with both .properties and YAML format in the same location, .properties takes precedence.

如果 properties 和 yaml 文件都存在,properties 文件优先。

相关推荐
逍遥德16 小时前
SpringBoot数据库连接池HikariCP,Druid,Tomcat JDBC,DBCP2,c3p0配置使用
数据库·spring boot·tomcat
万邦科技Lafite16 小时前
京东开放API接口:item_get返回参数指南
java·前端·javascript·api·电商开放平台
曹牧16 小时前
Java:处理 HTTP 请求的 Content-Type
java·开发语言
学术阿凡提16 小时前
Spring Boot 集成 Fastjson2 完整教程:从入门到避坑
spring boot·安全·json
SamDeepThinking16 小时前
第1篇-开篇词:几亿用户规模下,我们是怎么做C端高并发商品系统的
java·后端·架构
weisian15116 小时前
Java并发编程--47-分布式ID生成器:雪花算法(Snowflake)与时钟回拨问题
java·算法·时钟回拨·雪花算法id
itzixiao16 小时前
L1-066 猫是液体(5分)[java][python]
java·开发语言·python·算法
冷小鱼16 小时前
MyBatis 与 MyBatis-Plus:从入门到精通的完整指南
java·tomcat·mybatis
DolphinScheduler社区16 小时前
DolphinScheduler 3.3.2 如何调用 DataX 3.0 + SeaTunnel 2.3.12?附 Demo演示!
java·spark·apache·海豚调度·大数据工作流调度
亦暖筑序17 小时前
AI 客服系统安全加固:JWT 鉴权 + Bucket4j 三层限流
java·架构