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 文件优先。

相关推荐
计算机学姐1 天前
基于微信小程序的高校班务管理系统【2026最新】
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
一路向北⁢1 天前
基于 Apache POI 5.2.5 构建高效 Excel 工具类:从零到生产级实践
java·apache·excel·apache poi·easy-excel·fast-excel
毕设源码-赖学姐1 天前
【开题答辩全过程】以 基于Android的校园快递互助APP为例,包含答辩的问题和答案
java·eclipse
damo011 天前
stripe 支付对接
java·stripe
麦麦鸡腿堡1 天前
Java的单例设计模式-饿汉式
java·开发语言·设计模式
假客套1 天前
Request method ‘POST‘ not supported,问题分析和解决
java
傻童:CPU1 天前
C语言需要掌握的基础知识点之前缀和
java·c语言·算法
爱吃山竹的大肚肚1 天前
@Valid校验 -(Spring 默认不支持直接校验 List<@Valid Entity>,需用包装类或手动校验。)
java·开发语言
雨夜之寂1 天前
mcp java实战 第一章-第一节-MCP协议简介.md
java·后端
摇滚侠1 天前
Spring Boot 3零基础教程,WEB 开发 Thymeleaf 核心语法 笔记39
spring boot·笔记·后端·thymeleaf