配置项会按照一定优先级进行加载,优先级从高到低的顺序如下:
- 命令行参数
- 来自java:comp/env的JNDI属性
- JAVA系统属性(System.getProperties())
- 操作系统环境变量
- RandomValuepropertySource配置的random.*属性值
- jar包外部的application-{profile}.properties 或 application-{profile}.yml (带spring.profile) 配置文件。
- jar 包内部的application-{profile}.properties或application-{profile}.yml(带spring.profile) 配置文件。
- jar包外部的application.properties 或 application.yml (不带spring.profile) 配置文件。
- jar 包内部的application.properties或application.yml(不带spring.profile) 配置文件。
- @Configuration注解类上的@PropertySource
- 通过SpringApplication.setDefaultProperties指定的默认属性