springboot使用profile指定不同配置(尚硅谷)

 

 springboot扫描配置文件优先级分别是(高优先级覆盖低优先级,不同内容的配置形成互补的配置):

file:./config/  file:./  classpath:/config/ classpath:/

手动指定配置文件路径:

java -jar xxx.jar --spring.config.location=g:/application.properties

使用场景:项目已经打包了,修改了配置文件,无需再次打包,命令行重新指定修改后的配置文件路径

用法1:配置文件内激活

主配置文件application.properties(使用application-dev.properties)

debug=true

spring.profiles.active=dev

application.yml配置方法:

server:
 profiles: dev

开发环境配置文件 application-dev.properties

server.port=8081

生产环境配置文件application-product.properties

debug=false
server.port=80

用法2:命令行

1、命令行参数

java -jar xxx.jar --sring.profies.active=dev

 2、JVM参数

java -jar -Dspring.profiles.active=dev xxx.jar

原文地址:https://www.cnblogs.com/passedbylove/p/12640613.html