maven pom.xml加载不同properties配置[转]
可以参考http://www.openwebx.org/docs/autoconfig.html
1.pom.xml
===========================
<!-- 不同的打包环境配置: test=开发/测试测试环境, product=生产环境; 命令行方式: mvn clean install -Dmaven.test.skip=true -Ptest 或 -Pproduct-->
<profiles>
<!-- 开发/测试环境,默认激活 -->
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!--默认启用的是dev环境配置-->
</activation>
</profile>
<!-- 预发布环境 -->
<profile>
<id>preproduction</id>
<properties>
<env>preproduction</env>
</properties>
</profile>
<!-- 生产环境 -->
<profile>
<id>production</id>
<properties>
<env>production</env>
</properties>
</profile>
</profiles>
<build>
<filters> <!-- 指定使用的 filter -->
<filter>src/main/filters/filter-${env}-env.properties</filter>
</filters>
<resources>
<resource> <!-- 配置需要被替换的资源文件路径, db.properties 应该在 src/main/resource 目录下 -->
<directory>src/main/resources</directory>
<filtering>true</filtering> <!-- 是否使用过滤器 -->
</resource>
</resources>
</build>
2.src/main/filters/下不同环境的配置文件
src/main/filters/filter-preproduction-env.properties
src/main/filters/filter-production-env.properties
src/main/filters/filter-test-env.properties
======filter-test-env.properties 举例
jdbc.url=jdbc:mysql://192.168.120.220:3306/testdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=testuser
jdbc.password=123456
3.src/main/resources下要应用处理的文件
src/main/resources/conf/db.properties
======db.properties
jdbc.datasource=com.mchange.v2.c3p0.ComboPooledDataSource
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
jdbc.minPoolSize=10
jdbc.maxPoolSize=50
jdbc.autoCommit=false
-----------------------------------
自定义配置属性:
Custom properties in the POM
User defined properties in the pom.xml.
<project>
...
<properties>
<my.filter.value>hello</my.filter.value>
</properties>
...
</project>
- ${my.filter.value } will result in hello if you inserted the above XML fragment in your pom.xml
再比如:在pom.xml中properties自定义如下:
- <properties>
- <springframework_version>3.1.0.RELEASE</springframework_version>
- <maven.bbs.appConfig>itConfig.xml</maven.bbs.appConfig>
- </properties>
在web容器加载的时候,假如spring监听的配置文件是:applicationContext.xml,那么applicationContext.xml文件内容可以这样写来引入maven的properties属性值:
<import resource="${maven.bbs.appConfig}"/>
maven编译过后,targer项目里面的applicationContext.xml里面相应的引入就会变成
<import resource="itConfig.xml"/>
<build>
<!-- autoconfig with antx.properties -->
<filters>
<filter>${filterFile}</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build> <profiles>
<profile>
<id>dev</id>
<properties>
<filterFile>antx.properties</filterFile>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles> 现在发现有两种可以实现配置
一种是使用filter
第二种是使用
autoconfig-maven-plugin 来产生autoconfig
maven pom.xml加载不同properties配置[转]的更多相关文章
- maven pom.xml加载不同properties配置
1.pom.xml =========================== <!-- 不同的打包环境配置: test=开发/测试测试环境, product=生产环境; 命令行方式: mvn c ...
- maven项目pom.xml加载本地jar,自定义jar
将jar放到resource目录下面: pom添加配置 <!-- 加载IK自定义 依赖--> <dependency> <groupId>com.ik.up< ...
- 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样
[参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...
- (转)Maven pom.xml 配置详解
背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...
- Maven(四-2) Maven pom.xml 配置详解
转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...
- Maven pom.xml 全配置(二)不常用配置
Maven pom.xml 全配置(二)不常用配置 这里贴出Maven pom.xml文件中使用率较少的配置参数,如果此篇文档中没有找到你想要的参数,移步Maven pom.xml 全配置(一)常用配 ...
- Maven pom.xml 全配置(一)常用配置
Maven pom.xml 全配置(一)常用配置 这里贴出一个Maven中出现频率较高的配置参数注释,方便理解项目中Maven的配置具体的作用.如果在此博文中没有找到你想看到的参数,可以移步Maven ...
- web工程中web.xml元素加载顺序以及配置实例
简介 web.xml是web工程的配置文件,容器加载web工程时,会首先从WEB-INF中查询web.xml,并加载其中的配置信息,可以将web.xml认为是web工程的入口. web.xml中包含有 ...
- myeclipse maven pom.xml 配置错误
http://www.oschina.net/question/2265006_219341#tags_nav maven pom.xml 配置文件错误 腾讯云消息队列CMQ架构解析> ...
随机推荐
- Elasticsearch静态集群配置
这两天需要将ELK中的单节点运行的ES扩展为双节点,查询了下集群配置,百度搜索结果还是一如既往的坑,基本都是各种转帖,以下记录配置静态集群的步骤: * * * <pre><code& ...
- 【POJ 2406】Power Strings(KMP循环节)
终于靠着理解写出KMP了,两种KMP要代码中这种才能求循环节.i-next[i]就是循环节. #include<cstdio> #define N 1000005 char s[N]; i ...
- the useful for loop
cp four_letter four_letter_bk for i in `ls /media/10TB/Stats/Assembly_marker` do cd /media/10TB/Stat ...
- Oracle触发器反向调用Java程序
导入jar包 在oracle中导入需要的jar包,我们把编辑好的java类打成jar包,直接在oarcle里面写简单的调用就可以了, 1.操作系统需要拥有支持loadjava命令的jdk. 2.加载j ...
- viewport ---移动端详解
转自---http://www.cnblogs.com/2050/p/3877280.html 移动前端开发之viewport的深入理解 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上 ...
- 【BZOJ-1576】安全路径Travel Dijkstra + 并查集
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1044 Solved: 363[Sub ...
- 【uoj128】 NOI2015—软件包管理器
http://uoj.ac/problem/128 (题目链接) 题意 给出一棵树,每个节点代表一个软件包,维护卸载和安装操作.若要卸载节点x,那么必须卸载它的子树上的所有软件包:若要安装节点x必须安 ...
- Jenkins配置MSBuild时使用环境变量
[MSBuild Plugin]插件在使用环境变量有个很奇葩的方式,比如我们通常在Windows的节点机器上,使用WORKSPACE环境变量时,批处理应该这样写%WORKSPACE%,而有时插件确不能 ...
- Spring表单参数绑定中对“is”开头的boolean类型字段的的处理
之前在新浪微博上面发了一个微薄: 弱弱的发现在定义boolean类型的时候最好不要使用“is”开头,可以避免一些问题哦 然后有一些朋友朋友问我为什么,当时比较忙,现在写篇文章举一个例子,回复一下这个问 ...
- AngularJs ngReadonly、ngSelected、ngDisabled
ngReadonly 该指令将input,textarea等文本输入设置为只读. HTML规范不允许浏览器保存类似readonly的布尔值属性.如果我们将一个Angular的插入值表达式转换为这样的属 ...