springboot配置文件

#配置文件加载位置
springboot启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件
file:./config
file:./
classpath:/config/
classpath:/
优先级由高到低,高优先级会覆盖低优先级的配置;
SpringBoot从这四个位置全部加载,形成互补;
可以通过spring.config.location来修改默认的配置文件位置
项目打包好之后我们可以使用命令行参数的形式,启动项目的时候来指定配置文件的新位置,指定配置文件和默认加载的这些配置文件共同起作用形式形成互补
java -jar spring-boot-02.jar --spring.config.location=D:/application.properties
#外部配置加载顺序
SpringBoot可以从以下位置加载,优先级由高到低,形成互补。
命令行参数
java -jar spring-boot.jar --server.port=8081 --server.context-path=/hello
来自java:comp:/env的JNDI属性
java系统属性(System.getProperties())
操作系统环境变量
RandomValuePropertySource配置的random.*属性值
jar包外部的application-{profile}.properties或application.yml(带spring.profile)
jar包内部的application-{profile}.properties或application.yml(带spring.profile)
jar包外部的application-{profile}.properties或application.yml(不带spring.profile)
jar包内部的application-{profile}.properties或application.yml(不带spring.profile)
@Configuration注解类上的@PropertySource
通过SpringApplication.setDefaultProperties指定的默认属性
原文地址:https://www.cnblogs.com/kylingx/p/12945771.html