Profile配置

profile是spring用来针对不同的环境对不同的配置提供支持的,全局profile配置使用application-{profile}.properties(如application-prod.properties).

通过在application.properties中设置sprig.profiles.active = prod来指定活动的Profile。

若分两种环境生产(prod)和开发(dev)环境,生产环境下的端口号为80,开发环境下的端口号为8888

1、新建SpringBoot项目

2、生产和开发环境下的配置文件

    application-prod.properties:

server.port=80

    application-dev.properties:

server.port=8888

这是在项目工程中存在两份properties文件

3、运行:

  application.properties增加:

spring.profiles.active=dev

  修改application.properties:

spring.profiles.active=prod
原文地址:https://www.cnblogs.com/yourGod/p/9208380.html