3-3.多环境开发(properties多文件版)
约 174 字小于 1 分钟
2025-06-23
Spring Boot 最早期提供的配置文件格式是 properties 格式,本节介绍如何使用 properties 格式进行多环境配置。
1. 主配置文件
主配置文件用于指定当前激活的环境。
spring.profiles.active=pro
spring.profiles.active
属性用于设置当前激活的环境,上述配置表示激活 pro
环境。
2. 环境配置文件
环境配置文件用于定义特定环境下的配置。命名规则为 application-{环境名}.properties
。
application-pro.properties
server.port=80 # pro 环境下的端口号为 80
application-dev.properties
server.port=81 # dev 环境下的端口号为 81