springboot配置项目启动环境profile

转载自:http://www.5180it.com:8080/bbs/admin/1/506.html

我们在springBoot通常指定不同的配置环境,profile针对不同环境对不同的配置提供支持,全局配置profile配置使用application-*.properties.

比如

application-prod.properties    表示生产环境配置文件

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

application-test.properties       表示测试环境配置文件

我总结了下面3种方式

1、通过配置文件

通过在application.properties 中设置

spring.profiles.active=prod

来指定活动的profile

2、通过启动时指定环境

nohup java -jar xxx.jar --spring.profiles.active=prod&

3、配置服务器/etc/profile文件指定当前服务器上默认的profile

SPRING_PROFILES_ACTIVE=prod

export PATH JAVA_HOME SPRING_PROFILES_ACTIVE

修改完/etc/profile后保存,执行source /etc/profile 才能生效

source /etc/profile

这个启动时,即使不指定环境也可以默认为prod



转载自:http://www.5180it.com:8080/bbs/admin/1/506.html

你可能感兴趣的:(springboot配置项目启动环境profile)