SpringBoot 多Profile使用与切换方式

2025-05-29 0 69

SpringProfile对不同环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境。

文件名格式:application-{profile}.properties
可以建立多个properties(yaml)文件来不断的切换

application-dev.properties

?

1
server.port=8082

application-prod.properties

?

1
server.port=8083

application.properties

?

1

2
server.port=8081

spring.profiles.active=dev

SpringBoot 多Profile使用与切换方式

文件名格式:application-{profile}.yaml

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20
server:

port: 8082

spring:

profiles:

active: dev

---

spring:

profiles: dev

server:

port: 8083

---

spring:

profiles: prod

server:

port: 8084

---

spring:

profiles: default (未指定时默认使用的配置)

server:

port: 80

激活方式:

?

1

2

3

4

5

6

7
yaml中:

spring:

profiles:

active: dev

properties中:

spring.profiles.active=dev

运行时:

在打包后运行的时候,添加参数:

?

1
java -jar spring-boot.jar --spring.profiles.active=dev;

tomcat 中 catalina.bat(.sh中不用“set”) 添加JAVA_OPS。通过设置active选择不同配置文件:set JAVA_OPTS="-Dspring.profiles.active=test"

web.xml方式

spring.profiles.active prod
标注方式(junit单元测试非常实用)
@ActiveProfiles({“dev”})

到此这篇关于SpringBoot 多Profile使用切换方式的文章就介绍到这了,更多相关SpringBoot 多Profile使用切换内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!

原文链接:https://blog.csdn.net/qq_40742949/article/details/115488008

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 SpringBoot 多Profile使用与切换方式 https://www.kuaiidc.com/108290.html

相关文章

发表评论
暂无评论