SpringBoot多环境开发与日志小结
作者:十八岁讨厌编程 时间:2021-09-18 19:05:44
前置导入
什么是多环境?其实就是说你的电脑上写的程序最终要放到别人的服务器上去运行。每个计算机环境不一样,这就是多环境。常见的多环境开发主要兼顾3种环境设置,开发环境——自己用的,测试环境——自己公司用的,生产环境——甲方爸爸用的。因为这是绝对不同的三台电脑,所以环境肯定有所不同,比如连接的数据库不一样,设置的访问端口不一样等等。
多环境开发(yaml单一文件版)
那什么是多环境开发?就是针对不同的环境设置不同的配置属性即可。比如你自己开发时,配置你的端口如下:
server:
port: 80
如何想设计两组环境呢?中间使用三个减号分隔开
server:
port: 80
---
server:
port: 81
如何区分两种环境呢?起名字呗
spring:
profiles: pro
server:
port: 80
---
spring:
profiles: dev
server:
port: 81
那用哪一个呢?设置默认启动哪个就可以了
spring:
profiles:
active: pro# 启动pro
---
spring:
profiles: pro
server:
port: 80
---
spring:
profiles: dev
server:
port: 81
就这么简单,再多来一组环境也OK
spring:
profiles:
active: pro# 启动pro
---
spring:
profiles: pro
server:
port: 80
---
spring:
profiles: dev
server:
port: 81
---
spring:
profiles: test
server:
port: 82
其中关于环境名称定义上述格式是过时格式,标准格式如下
spring:
config:
activate:
on-profile: pro
来源:https://blog.csdn.net/zyb18507175502/article/details/126269722
标签:SpringBoot,多环境,开发
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java数据结构BFS广搜法解决迷宫问题
2023-12-03 16:04:33
![](https://img.aspxhome.com/file/2023/4/63304_0s.png)
大白话讲解C# 中的委托
2023-02-03 02:06:41
![](https://img.aspxhome.com/file/2023/0/69200_0s.jpg)
C#实现文件上传与下载功能实例
2022-11-18 07:59:03
spring-boot整合ehcache实现缓存机制的方法
2023-06-18 20:05:10
java关键字final使用方法详解
2023-11-28 22:38:04
Hibernate实现悲观锁和乐观锁代码介绍
2022-04-25 09:43:45
Spring Boot 2.5.0 重新设计的spring.sql.init 配置有啥用
2021-12-04 00:04:43
关于Java中HashCode方法的深入理解
2022-05-28 03:29:33
![](https://img.aspxhome.com/file/2023/1/75791_0s.png)
Springcloud微服务架构基础知识解析
2023-01-26 14:37:10
![](https://img.aspxhome.com/file/2023/0/61820_0s.png)
java web中 HttpClient模拟浏览器登录后发起请求
2022-10-27 23:07:05
android效果TapBarMenu绘制底部导航栏的使用方式示例
2023-07-29 20:53:36
![](https://img.aspxhome.com/file/2023/2/84722_0s.gif)
JAVA随机打乱数组顺序的方法
2023-08-11 18:56:03
解决JAVA遍历List集合,删除数据时出现的问题
2021-12-25 15:38:03
如何使用java修改文件所有者及其权限
2023-11-16 09:35:53
![](https://img.aspxhome.com/file/2023/9/76309_0s.png)
Java编程基础测试题分享
2023-11-27 22:14:58
详解java 中Spring jsonp 跨域请求的实例
2023-11-19 02:48:18
![](https://img.aspxhome.com/file/2023/7/59667_0s.png)
Java JDK动态代理实现原理实例解析
2022-04-23 05:19:10
Java 根据网址查询DNS/IP地址的方法
2023-06-21 15:31:54
Spring Data环境搭建实现过程解析
2022-02-26 20:13:38
在AOP中Spring生成代理类的两种方式
2023-12-08 19:13:36