Spring boot 的Application.properties 配置文件可以是以下幾個地方:
classpath:/,classpath:/config/,file:./,file:./config/.
但要注意的是加載的順序是倒過來的:
file:./config/
file:./
classpath:/config/
classpath:/
可以通過spring.config.location增加自定義的配置文件存放目錄,比如:
classpath:/custom-config/,file:./custom-config/
那么最終的尋找路徑是:
file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/
可以通過spring.config.name 修改默認的配置文件名稱,比如:
$ java -jar myproject.jar --spring.config.name=myproject
可以通過spring.config.location指定配置文件,比如:
$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
可以通過spring.config.location指定配置文件的位置,比如:
$ java -jar myproject.jar --
spring.config.additional-location=classpath:/custom-config/,file:./custom-config/