Maven启动指定Profile通过-P,如mvn spring-boot:run -Ptest
,但这是Maven的Profile。
如果要指定spring-boot的spring.profiles.active
,spring-boot 1.x 使用mvn spring-boot:run -Drun.profiles=test
,spring-boot 2.x 使用mvn spring-boot:run -Dspring-boot.run.profiles=test
。
参考资料
- https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-profiles.html
- https://docs.spring.io/spring-boot/docs/2.3.7.RELEASE/maven-plugin/reference/html/#run-example-active-profiles
如果使用命令行直接运行jar文件,则使用java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar
如果使用开发工具,运行Application.java文件启动,则增加参数--spring.profiles.active=test