生產(chǎn)中會(huì)經(jīng)歷,開發(fā),測(cè)試,到上線。三個(gè)階段
這個(gè)三個(gè)階段,都有各自的配置文件,如果只是一個(gè)配置文件來(lái)回改
會(huì)很容易出現(xiàn)錯(cuò)誤的,那么springboot提供了很簡(jiǎn)答的解決辦法
使用spring.profiles.active=test
-
定義一個(gè)application.properties 里面寫上
- spring.profiles.active=test 默認(rèn)啟動(dòng)test文件
定義application-dev.properties
定義application-test.properties
定義application-prod.properties
使用java -jar mm.jar --spring.profiles.active=dev 運(yùn)行啟動(dòng)dev環(huán)境
可以看到啟動(dòng)的是dev
2017-01-04 18:54:11.095 INFO 43026 --- [ restartedMain] dragonfly.DragonflyApplication : Starting DragonflyApplication on KK-MINI.local with PID 43026 (/Users/liuxin/git/oto_saas_mybosc_pay/target/classes started by liuxin in /Users/liuxin/git/oto_saas_mybosc_pay)
2017-01-04 18:54:11.100 INFO 43026 --- [ restartedMain] dragonfly.DragonflyApplication : The following profiles are active: dev