简介:Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活,指定参数等方式快速切换环境
1.多profile文件形式
- 格式 : application-{profile}.properties/yml
- application-one.properties application-two.properties
默认使用application.properties文件的配置,可以在里面指定需要激活的环境
- 配置文件 : spring.profiles.active=one


spring.profiles.active=one


2.yml配置文件多profile文档块模式:
server:
port: 8081
spring:
profiles:
active: one
---
server:
port: 8082
spring:
profiles: one
---
server:
port: 8083
spring:
profiles: two

3.激活方式:
- 命令行 : --spring.profiles.active=one


在cmd窗口中的命令行:

- jvm(虚拟机)参数 : -Dspring.profiles.active=one (-D是固定写法)

推荐使用yml多文档块方式配置!
本文详细介绍Spring框架中Profile功能的使用,包括多环境配置文件的创建、YAML多文档块配置方式及激活Profile的方法,适用于快速切换开发、测试、生产等不同环境。
767

被折叠的 条评论
为什么被折叠?



