Spring Boot 的配置加载顺序
配置的加载
Spring Boot 可以从 properties 文件、YAML 文件、环境变量和命令行参数获取配置。默认 SpringApplication 将从如下位置加载 application.properties 或 application.yml 文件作为配置。
java -jar project.jar --spring.config.location=/path/to/application.yml- ......
- A
/configsubdir of the current directory(application.propertiesorapplication.yml) - The current directory(
application.propertiesorapplication.yml) - A classpath
/configpackage(application.propertiesorapplication.yml) - The classpath root(
application.propertiesorapplication.yml) @PropertySource或者@PropertySourcesannotations on your@Configurationclasses- Default properties (specified using
SpringApplication.setDefaultProperties)
根据配置加载的顺序,前面的配置将会覆盖后面的配置项。常见的配置
Copyright © 2015 Powered by MWeb, Theme used GitHub CSS.