A note from book Spring boot in Action, 1st edition by Craig Walls , chapter 3:
There are, in fact, several ways to set properties for a Spring Boot application. Spring Boot will draw properties from several property sources, including the following:
- Command-line arguments
- JNDI attributes from java:comp/env
- JVM system properties
- Operatiing system environment variables
- Randomly generated values for properties prefixed with random.* (referenced when setting other properties, such as ${random.long})
- An application.properties or application.yml file outside of the application
- An application.properties or application.yml file packaged inside of the application
- Property sources specified by @PropertySource
- Default properties
This list is in order of precedence. That is, any properties set from a source higher in the list will override the same property set on a source lower in the list.
This can be verified in Spring boot source code. I will try to dig and document it when I go to that.
本文探讨了SpringBoot应用程序中属性设置的多种方式及其优先级。从命令行参数到默认属性,详细阐述了如何覆盖及设定应用配置,为开发者提供全面的SpringBoot配置管理指南。
1173

被折叠的 条评论
为什么被折叠?



