Spring Boot配置加载顺序
如果加载的配置有重复的,它们的加载顺序是这样的,数字越小的优先级越高,即优先级高的覆盖优先级低的配置。
- Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
- @TestPropertySource annotations on your tests.
- @SpringBootTest#properties annotation attribute on your tests.
- Command line arguments.
- Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
- ServletConfig init parameters.
- ServletContext init parameters.
- JNDI attributes from java:comp/env.
- Java System properties (System.getProperties()).
- OS environment variables.
- A RandomValuePropertySource that only has properties in random.*.
- Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
- Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
- Application properties outside of your packaged jar (application.properties and YAML variants).
- Application properties packaged inside your jar (application.properties and YAML variants).
- @PropertySource annotations on your @Configuration classes.
- Default properties (specified using SpringApplication.setDefaultProperties).
知道了它们的加载顺序,我们就能知道从哪一步来替换配置。
推荐阅读
分享Java干货,高并发编程,热门技术教程,微服务及分布式技术,架构设计,区块链技术,人工智能,大数据,Java面试题,以及前沿热门资讯等。
关注微信公众号福利!!!
回复关键字「666」获取一份最新 Java 架构资料,你要的都有!
回复关键字「Java」获取JVM, 多线程等Java技术系列教程;
回复关键字「spring」获取Spring, Spring Boot, Spring Cloud教程;
回复关键字「架构」获取分布式、微服务、架构、高并发等系列干货;
回复关键字「面试」获取各种 Java 面试题及答案、面试实战经验;