Spring Boot 支持多种外部配置方式
官方优先级:链接:link
SpringBoot可以从以下位置获取配置 优先级由高到低
1.命令行参数
java -jar xxx.jar --server.port=9090 --server.context-path=/test
多个配置用空格隔开
2.来自java:comp/env的JNDI属性
3.Java系统属性 (System.getProperties())
4.操作系统环境变量
5.RandomValuePropertySource配置的random.*属性
优先加载带profile
6.jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件
7.jar包内部的application-{profile}.properties或application.yml(带spring.profile)配置文件
8.jar包外部的application.properties或application.yml(不带spring.profile)配置文件
9.jar包内部的application.properties或application.yml(不带spring.profile)配置文件
10.@Configuration注解上的@PropertySource
11.通过SpringApplication.setDefaultProperties指定默认属性