Maven啟動指定Profile通過-P,如mvn spring-boot:run -Ptest
,但這是Maven的Profile。
如果要指定spring-boot的spring.profiles.active
,則必須使用mvn spring-boot:run -Drun.profiles=test
如果使用命令行直接運行jar文件,則使用java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar
如果使用開發工具,運行Application.java文件啟動,則增加參數--spring.profiles.active=test
https://docs.spring.io/spring-boot/docs/current/maven-plugin/examples/run-profiles.html
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.2.1.RELEASE</version> <configuration> <profiles> <profile>foo</profile> <profile>bar</profile> </profiles> </configuration> ... </plugin> ... </plugins> ... </build> ... </project>
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar