Maven之profile实现多环境配置动态切换
一、多环境配置文件的放置
- development:开发环境
- testing:测试环境
- production:生产环境

二、pom文件的配置
(1)配置profile
<profiles>
<profile>
<!-- 开发环境 -->
<id>development</id>
<properties>
<profiles.active>development</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<id>testing</id>
<properties>
<profiles.active>testing</profiles.active>
</properties>
</profile>
<profile>
<!-- 生产环境 -->
<id>production</id>
<properties>
<profiles.active>production</profiles.active>
</properties>
</profile>
</profiles>
x
<profiles>
<profile>
<!-- 开发环境 -->
<id>development</id>
<properties>
<profiles.active>development</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<id>testing</id>
<properties>
<profiles.active>testing</profiles.active>
</properties>
</profile>
<profile>
<!-- 生产环境 -->
<id>production</id>
<properties>
<profiles.active>production</profiles.active>
</properties>
</profile>
</profiles>
(2)配置maven资源文件打包规则
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 这个filter必须要设为true, 把所有文件都过滤掉,然后下面再手动include,一个一个文件夹自己添加 -->
<filtering>true</filtering>
<includes>
<include>spring/*</include>
</includes>
</resource>
<resource>
<!-- 这里会直接把${profiles.active}对应文件夹下的内容打包到classpath下 -->
<directory>src/main/resources/${profiles.active}</directory>
</resource>
</resources>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 这个filter必须要设为true, 把所有文件都过滤掉,然后下面再手动include,一个一个文件夹自己添加 -->
<filtering>true</filtering>
<includes>
<include>spring/*</include>
</includes>
</resource>
<resource>
<!-- 这里会直接把${profiles.active}对应文件夹下的内容打包到classpath下 -->
<directory>src/main/resources/${profiles.active}</directory>
</resource>
</resources>
三、如何在Spring配置文件中读取这些不同环境下的propertis文件
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:redis-config.properties</value>
<value>classpath:dubbo-client.properties</value>
<value>classpath:rabbitmq-config.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:redis-config.properties</value>
<value>classpath:dubbo-client.properties</value>
<value>classpath:rabbitmq-config.properties</value>
</list>
</property>
</bean>
四、如何打包
Maven之profile实现多环境配置动态切换的更多相关文章
- (十一)Maven之profile实现多环境配置动态切换
原文链接:https://www.cnblogs.com/zeng1994/p/a442108012ffd6a97b22c63055b48fe9.html 一.多环境配置文件的放置 将不同环境下的配 ...
- maven 利用 profile 进行多环境配置
我们在进行项目的多环境配置时,有很多种方式供我们选择,比如 SpringBoot 自带的 application-dev.yml.maven 的 profile 等.这里介绍的就是如何利用 profi ...
- 使用maven的profile构建不同环境配置
基本概念说明(resources.filter和profile): 1.profiles定义了各个环境的变量id 2.filters中定义了变量配置文件的地址,其中地址中的环境变量就是上面profil ...
- SpringBoot Profiles 多环境配置及切换
目录 前言 默认环境配置 多环境配置 多环境切换 小结 前言 大部分情况下,我们开发的产品应用都会根据不同的目的,支持运行在不同的环境(Profile)下,比如: 开发环境(dev) 测试环境(tes ...
- 通过maven profile 打包指定环境配置
背景 最近换了个新公司接手了一个老项目,然后比较坑的是这个公司的项目都没有没有做多环境打包配置,每次发布一个环境都要手动的去修改配置文件.今天正好有空就来配置下. 解决这个问题的方式有很多,我这里挑选 ...
- maven profile实现多环境配置
每次项目部署上线都需要手动去修改配置文件(比如数据库配置,或者一个自定义的配置)然后才能打包,很麻烦,网上找到 maven profile可以完成这个工作,记录如下: 环境:eclipse + spr ...
- 使用maven profile实现多环境配置相关打包
项目开发需要有多个环境,一般为开发,测试,预发,正式4个环境,通过maven可以实现按不同环境进行打包部署,命令为: mvn package -P dev 在eclipse中可以右击选项run con ...
- Spring boot 的profile功能如何实现多环境配置自动切换
通常服务端应用开发需要经过以下几个流程: 开发 -> 测试 -> RC验证 -> 上线 这就涉及到四个不同的环境,开发环境.测试环境.RC环境以及生产环境,为了避免不同环境之间相互干 ...
- spring boot:基于profile的多环境配置(spring boot 2.3.4)
一,为什么要进行多环境配置? 1,没有人会在生产环境中进行开发和测试, 所以通常会有多个环境的划分: 工程师本地的开发环境 进行测试的测试环境 最终上线的生产环境 每个环境对应不同的数据库/缓存等数据 ...
随机推荐
- mysql左连接
举个例子说明: select d.id, d.uid,d.username,d.dateline, d.message,d.replynum, c.picid, c.filename from doi ...
- Android 消息异步处理之AsyncTask
Android提供了异步处理消息的方式大致有两种,第一种是handler+Thread,之前已经对于这种方式做过分析,第二种就是AsyncTask,这是Android1.5提供的一种轻量级的工具类,其 ...
- Linux 源码阅读 进程管理
Linux 源码阅读 进程管理 版本:2.6.24 1.准备知识 1.1 Linux系统中,进程是最小的调度单位: 1.2 PCB数据结构:task_struct (Location:linux-2. ...
- Docker Data Center系列(四)- 离线安装UCP和DTR
本系列文章演示如何搭建一个mini的云平台和DevOps实践环境. 基于这套实践环境,可以部署微服务架构的应用栈,演练提升DevOps实践能力. 1 离线安装UCP 1.1 可用版本 Version ...
- 使用Visual Studio Team Services持续集成(二)——为构建定义属性
使用Visual Studio Team Services持续集成(二)--为构建定义属性 1.从VSTS帐户进入到Build 2.编辑构建定义并单击Options Description:如果这里明 ...
- c/c++ 标准库 map set 大锅炖
标准库 map set 大锅炖 一,关联容器有哪些 按关键字有序保存元素 map 保存key和value set 只保存key mulutimap key可以重复出现 multiset key可以重复 ...
- CMM/CMMI的基本概念
"CMM是指“能力成熟度模型”,其英文全称为Capability Maturity Model for Software,英文缩写为SW-CMM,简称CMM. 它是对于软件组织在定义.实施. ...
- no plugin found for prefix 'tomcat 7' in the current project and in the plugin groups的解决方法
解决方法一: 找到这个settings.xml文件,进行编辑,在pluginGroups标签下加入下面的配置 <pluginGroups><pluginGroup>org.ap ...
- 使用 cmd连接 Oracle,MySql,SQL Server 数据库
1. Oracle cmd连接数据库 语法: sqlplus 用户/口令(密码)@服务器IP/数据库实例名(SID) 1.1 方式一 数据库服务在本机上IP可以用localhost替换 sqlplus ...
- 联想ts550服务器安装windows2008R2系统
发布时间:2018-10-18 点击数:4 服务器型号:联想 thinkserver ts550 系统:windowsserver2008R2 联想的 TS550 USB口全是USB3.0的,官方引 ...