SpringBoot系列之基于maven多环境配置
实际开发过程中,配置的多环境区分属于标配了,当我们不考虑配置中心时,将多环境的配置就放在项目的resource目录下,那么可以怎样做多环境的配置管理呢?
之前介绍过一篇基于 spring.profiles.active 配置来选择对应的配置文件的方式,有了解这个配置的小伙伴可以很快找到这种方式的特点
如配置值为dev,则加载 application-dev.yml 配置文件,如果为prod,则加载 application-prod.yml
那么缺点就很明显了,当我每个环境的配置很多时,上面这种方式真的好用么?
接下来本文介绍另外一种常见的基于maven的多环境配置方式
I. 项目搭建
1. 项目依赖
本项目借助 SpringBoot 2.2.1.RELEASE + maven 3.5.3 + IDEA 进行开发
开一个web服务用于测试
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
一个简单的页面模板
resources/templates/index.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="SpringBoot thymeleaf&#