Spring Boot使用特定顺序查找属性:
- 命令行参数
- Java系统属性(
System.getProperties()
) - 操作系统环境变量
- 来自的JNDI属性
java:comp/env
- 一个
RandomValuePropertySource
只有在性能random.*
- 打包的jar之外的应用程序属性(
application.properties
包括YAML和配置文件变体) - 打包在jar中的应用程序属性(
application.properties
包括YAML和配置文件变体) @PropertySource``@Configuration
课堂上的注释- 默认属性(使用指定
SpringApplication.setDefaultProperties
)
若要使使用自定义启动器的项目在如何覆盖默认值方面具有最大的灵活性,应使用一种尽可能接近上述列表末尾的机制。鉴于您已经拥有自己的子类
SpringApplication,我将
SpringApplication.setDefaultProperties(Properties)在该子类中使用。



