springboot指定配置文件啓動

spring-boot:run啓動時,指定spring.profiles.active

例若有以下幾個配置文件html

application.properties中配有java

spring.profiles.active=dev

application-dev.properties 中配有spring

server.port=8081

application-test.properties 中配有app

server.port=8082

Maven啓動test配置指定Profile經過-P,如spring-boot

`mvn spring-boot:run -Ptest`,但這是Maven的Profile。

若是要指定spring-boot的spring.profiles.active,則必須使用工具

`mvn spring-boot:run -Drun.profiles=test`啓動test配置

若是使用命令行直接運行jar文件,則使用開發工具

`java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar`啓動test配置

若是使用開發工具,運行Application.java文件啓動,則增長參數命令行

`--spring.profiles.active=test`啓動test配置

dev是默認的配置code

例如:application-dev.properties文件名dev 和啓動spring.profiles.active=dev的dev相對應
相關文章
相關標籤/搜索