Spring Boot实战(六)Spring Boot核心 6.4 Profile配置

Profile是Spring用来针对不同的环境下对不同的配置提供支持的,全局Profile配置使用application-{profile}.properties(如application-prod.properties)。
通过在application.properties中设置spring.profiles.active=prod来指定活动的Profile。
下面将做一个最简单的演示,如我们分为生产(prod)和开发(dev)环境,生产环境下端口号为80,开发环境下端口为8888。
实战
(1)新建Spring Boot 项目 如图。
在这里插入图片描述
在这里插入图片描述
(2)生产和开发环境下的配置文件如下:
application-prod.properties

server.port=80

application-dev.properties

server.port=8888

此时目录结构如图
在这里插入图片描述
(3)运行。
application.properties增加:

spring.profiles.active=prod

启动程序结果为
在这里插入图片描述
修改application.properties:

spring.profiles.active=dev

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40929047/article/details/86570420