SpringBoot 多Profile使用与切换方式
作者:C-Ray 时间:2022-04-13 14:58:27
Spring中Profile对不同环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境。
文件名格式:application-{profile}.properties
可以建立多个properties(yaml)文件来不断的切换
application-dev.properties
server.port=8082
application-prod.properties
server.port=8083
application.properties
server.port=8081
spring.profiles.active=dev
文件名格式:application-{profile}.yaml
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
激活方式:
yaml中:
spring:
profiles:
active: dev
或
properties中:
spring.profiles.active=dev
运行时:
在打包后运行的时候,添加参数:
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”})
来源:https://blog.csdn.net/qq_40742949/article/details/115488008
标签:SpringBoot,Profile,使用,切换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
springcloud之自定义简易消费服务组件
2022-01-29 00:18:24
![](https://img.aspxhome.com/file/2023/8/61878_0s.png)
JavaWeb dbutils执行sql命令并遍历结果集时不能查到内容的原因分析
2022-04-11 22:50:02
![](https://img.aspxhome.com/file/2023/8/72338_0s.png)
javassist使用指南
2023-03-04 17:03:00
解读List list=new ArrayList()是怎么回事
2022-04-17 12:28:22
![](https://img.aspxhome.com/file/2023/5/61145_0s.png)
C#策略模式(Strategy Pattern)实例教程
2022-11-29 07:35:07
![](https://img.aspxhome.com/file/2023/5/71075_0s.png)
Java List集合排序实现方法解析
2023-01-06 05:40:14
Java实现FTP上传与下载功能
2021-09-22 18:28:51
![](https://img.aspxhome.com/file/2023/0/62340_0s.jpg)
Spring Boot 配置和使用多线程池的实现
2022-09-04 19:53:02
Spring Boot配置AOP打印日志的全过程
2023-08-07 12:56:38
Java利用自定义注解实现数据校验
2022-12-03 09:56:49
Java基于Javafaker生成测试数据
2023-11-23 09:36:16
![](https://img.aspxhome.com/file/2023/5/58895_0s.png)
ClassLoader类加载源码解析
2023-11-25 18:17:09
![](https://img.aspxhome.com/file/2023/6/61826_0s.jpg)
java实现图片滑动验证(包含前端代码)
2022-03-21 12:13:52
![](https://img.aspxhome.com/file/2023/8/60538_0s.jpg)
C++实现无重复字符的最长子串
2023-11-02 22:49:00
只需两步实现Eclipse+Maven快速构建第一个Spring Boot项目
2023-08-03 23:47:43
![](https://img.aspxhome.com/file/2023/4/78354_0s.png)
使用C# Winform应用程序获取网页源文件的解决方法
2023-02-01 10:56:28
Springboot如何根据实体类生成数据库表
2023-11-20 13:54:39
![](https://img.aspxhome.com/file/2023/7/59677_0s.jpg)
Feign调用中的两种Header传参方式小结
2022-10-25 02:47:17
mybatis-plus update更新操作的三种方式(小结)
2023-10-08 14:05:08
![](https://img.aspxhome.com/file/2023/9/62639_0s.png)
Java 线程池ThreadPoolExecutor源码解析
2022-06-28 09:13:59
![](https://img.aspxhome.com/file/2023/7/64767_0s.png)