maven profile多环境动态配置文件使用
pom.xml
<profiles>
<!-- =====开发环境====== -->
<profile>
<id>dev</id>
<properties>
<env>dev</env>
<!-- 微服务配置 -->
<dubbo.version>server.hbd</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>192.16.8.126</redis.ip>
<redis.port>6379</redis.port>
<redis.pass>cor2017</redis.pass>
<!-- swagger接口 -->
<swagger.enable>true</swagger.enable>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<!-- =======UAT环境========== -->
<profile>
<id>uat</id>
<properties>
<env>uat</env>
<!-- 微服务配置 -->
<dubbo.version>server.positec</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>127.0.0.1</redis.ip>
<redis.port>15552</redis.port>
<redis.pass>positec2017...</redis.pass>
<!-- swagger接口 -->
<swagger.enable>true</swagger.enable>
</properties>
</profile>
<!-- ======生产环境====== -->
<profile>
<id>prod</id>
<properties>
<env>prod</env>
<!-- 微服务配置 -->
<dubbo.version>server.positec</dubbo.version>
<!-- redis缓存配置 -->
<redis.ip>127.0.0.1</redis.ip>
<redis.port>6379</redis.port>
<redis.pass>123</redis.pass>
<!-- swagger接口 -->
<swagger.enable>false</swagger.enable>
</properties>
</profile>
</profiles>
<build>
<resources>
<!-- 先指定 src/main/resources下所有文件及文件夹为资源文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
<!-- 设置对某些文件进行过滤, 这里对*.properties进行过虑,即这些文件中的${key}会被替换掉为真正的值 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!--<archiveClasses>true</archiveClasses>-->
<warName>${project.artifactId}</warName>
<!--<warSourceDirectory>${basedir}/src/main</warSourceDirectory>-->
<webappDirectory>${project.build.directory}/${project.artifactId}
</webappDirectory>
<webResources>
<resource>
<!-- 由于我是把配置文件都在/WEB-INF/config/文件夹-->
<!-- 所以把src/main/resources 被filter替换的文件替换dao WEB-INF/config/下-->
<directory>src/main/resources</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
spring boot application.properties配置文件
## spring boot 必须用@xx@符号, 不用${}
spring.profiles.active=@env@
#环境dev=开发, prod=生产, uat=用户测试
env=@env@
#IP
redis.ip=@redis.ip@
#Port
redis.port=@redis.port@
redis.pass=@redis.pass@
dubbo.zoo.connectString=@dubbo.zoo.connectString@
dubbo.version=@dubbo.version@
swagger.enable=@swagger.enable@
其他模块普通配置文件
redis.ip=${redis.ip}
#Port
redis.port=${redis.port}
redis.pass=${redis.pass}
spring boot 和普通的方式不同,需要用@@符号占位符,普通方式用${}符号占位
profiles可以被子模块继承,
<build><resources>配置很重要。
maven profile多环境动态配置文件使用的更多相关文章
- maven profile多环境自动切换配置,配置分离,排除文件
痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环境对项目的需求也不相同. 在此之前,我们往往需要手动去修改相对应的配置文件然后打成war,才能部 ...
- maven profile 多环境
<profiles> <profile> <!-- 本地开发环境 --> <id>dev</id> <properties> & ...
- (转载)maven profile多环境自动切换配置
原文:https://www.cnblogs.com/adeng/p/7059588.html 痛点: 在java开发的过程中,我们经常要面对各种各样的环境,比如开发环境,测试环境,正式环境,而这些环 ...
- maven profile动态选择配置文件
一.背景 在开发过程中,我们的软件会面对不同的运行环境,比如开发环境.测试环境.生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基本配 ...
- 使用maven profile指定配置文件打包适用多环境
新建maven项目, 在pom.xml中添加 profile节点信息如下: <profiles> <profile> <!-- 开发环境 --> <id& ...
- Spring boot项目分环境Maven打包,动态配置文件,动态配置项目
Spring boot Maven 项目打包 使用Maven 实现多环境 test dev prod 打包 项目的结构 在下图中可用看出,我们打包时各个环境需要分开,采用 application-环境 ...
- 项目实现不同环境不同配置文件-maven profile
最近接触的项目都是在很多地方都落地的项目,需要支持不同的环境使用不同的配置文件.一直以来都以为是人工的去写不同的配置文件,手动的去修改运用的配置文件.感觉自己还是太low呀.maven的使用的还停留在 ...
- 【转】maven profile实现多环境打包
作为一名程序员,在开发的过程中,经常需要面对不同的运行环境(开发环境.测试环境.生产环境.内网环境.外网环境等等),在不同的环境中,相关的配置一般不一样,比如数据源配置.日志文件配置.以及一些软件运行 ...
- Maven根据不同环境打包不同配置文件
开发项目时会遇到这个问题:开发环境,测试环境,生产环境的配置文件不同,打包时经常要手动更改配置文件,更改的少还可以接受,但是如果需要更多个配置文件,手动的方法就显得非常笨重了. 下面介绍一种方法,利用 ...
随机推荐
- 5.1 Zend_Log_Writer
22.2.2. 写入到数据库 22.2.3. 踩熄Writer 22.2.4. 測试 Mock 22.2.5. 组合Writers
- NYOJ 467 中缀式变后缀式
做了表达式求值那道题之后做的 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 人们的日常习惯是把算术表达式写成中缀式,但对于机器来说更"习惯于"后 ...
- 打印十字图 queue 搞定
题目描述 小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示: ..$$$$$$$$$$$$$.. ..$...........$.. $$$.$$$$$$$$$.$$$ $...$... ...
- SAP ECC6安装系列一:安装前硬件和软件准备
原作者博客 http://www.cnblogs.com/Michael_z/ ======================================== 写在前面的罗嗦话 一晃就是5年,前几天 ...
- 跟着百度学PHP[10]-读取COOKIE案例
<?php if(!isset($_COOKIE['visittime'])){ #使用$_COOKIE获取visittime,如果不存在就执行下面的语句块,否则执行else setcookie ...
- ubuntu -- mf210v拨号流程
1 脚本建立 Root权限进入Ubuntu,在 /etc/ppp/ 下面建立两个目录,如果有就不需要建立了.直接把脚本放进去或者建立新文件即可. cd /etc/ppp mkdir peers c ...
- SenCha Touch 与 EXTJS 安装Myeclipse 插件
http://www.cnblogs.com/jirimutu01/default.html 关于SenchaEclipsePlugin插件的安装和使用 使用过eclipse开发java程序的人都知道 ...
- Spring整合activiti单元测试
** * Spring测试activiti配置是否正常 * <p>Title: SpringActivitiTest</p> * <p>Description: & ...
- mysql数据库 详解
一.学习目录 1.认识数据库和mysql 2.mysql连接 3.入门语句 4.详解列类型 5.增删改查 INSERT INTO 表名(列1,…… 列n) VALUES(值 1,…… 值 n) ...
- eclipse 灵活使用makefile来编译C/C++
需求: 近期在看<C++ Primer Plus>, 作者在不断优化自己的类.有很多不同的版本号,有非常多的測试函数(main函数),我使用的是eclipse+CDT来编写C++,不可能为 ...