可以参考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自定义如下:

  1. <properties>
  2. <springframework_version>3.1.0.RELEASE</springframework_version>
  3. <maven.bbs.appConfig>itConfig.xml</maven.bbs.appConfig>
  4. </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配置[转]的更多相关文章

  1. maven pom.xml加载不同properties配置

    1.pom.xml =========================== <!-- 不同的打包环境配置: test=开发/测试测试环境,  product=生产环境; 命令行方式: mvn c ...

  2. maven项目pom.xml加载本地jar,自定义jar

    将jar放到resource目录下面: pom添加配置 <!-- 加载IK自定义 依赖--> <dependency> <groupId>com.ik.up< ...

  3. 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样

    [参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...

  4. (转)Maven pom.xml 配置详解

    背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...

  5. Maven(四-2) Maven pom.xml 配置详解

    转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom?    pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...

  6. Maven pom.xml 全配置(二)不常用配置

    Maven pom.xml 全配置(二)不常用配置 这里贴出Maven pom.xml文件中使用率较少的配置参数,如果此篇文档中没有找到你想要的参数,移步Maven pom.xml 全配置(一)常用配 ...

  7. Maven pom.xml 全配置(一)常用配置

    Maven pom.xml 全配置(一)常用配置 这里贴出一个Maven中出现频率较高的配置参数注释,方便理解项目中Maven的配置具体的作用.如果在此博文中没有找到你想看到的参数,可以移步Maven ...

  8. web工程中web.xml元素加载顺序以及配置实例

    简介 web.xml是web工程的配置文件,容器加载web工程时,会首先从WEB-INF中查询web.xml,并加载其中的配置信息,可以将web.xml认为是web工程的入口. web.xml中包含有 ...

  9. myeclipse maven pom.xml 配置错误

    http://www.oschina.net/question/2265006_219341#tags_nav maven pom.xml 配置文件错误       腾讯云消息队列CMQ架构解析> ...

随机推荐

  1. js-设置焦点

    function CheckForm() { if(document.form1.trainingName.value==""){ alert("培训班名称不能为空!&q ...

  2. jsrender for object

    <div id="result"></div> <script id="theTmpl" type="text/x-js ...

  3. C#-黑客-数据库访问-字符串的攻击和防御

    C#中用基本的方法对数据库进行增删改查,会被黑客利用,写入其他的代码以实现对数据库的数据进行其他的操作.例如: 对下列数据库的某个信息进行修改操作 修改代码: using System; using ...

  4. JS 初学正则表达式

    正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度 匹配中文:[\u4e00-\u9fa5] 英文字母:[a-zA-Z] 数字:[0-9] 匹配中文,英文字母和数字及_: ^[\u4e00- ...

  5. JS 打印功能代码可实现打印预览、打印设置等

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  6. win10下安装Ubuntu出现win10无法进入的情况

    昨天晚上在win10上安装Ubuntu Kylin16.04系统,结果发现重启的时候进不去windows系统了,而且报的错误是 /EndEntire file path: /ACPI(a0341d,0 ...

  7. 数据结构之二分查找(PHP)

    <?php //二分查找算法 //前提:索引数组.数组已排好顺序 $a=array(1,3,4,6,8,9,11,13,15,24,25,27,30,38); $search = 30;//要查 ...

  8. Value和Object的区别

    在使用NSMutableDictionary的时候经常会使用setValue forKey与setObject forKey,他们经常是可以交互使用的,代码中经常每一种的使用都有. 1,先看看setV ...

  9. UItextView回收键盘的几种方式

    1.如果你程序是有导航条的,可以在导航条上面加多一个Done的按钮,用来退出键盘,当然要先实UITextViewDelegate. 代码如下: - (void)textViewDidBeginEdit ...

  10. Leetcode 226. Invert Binary Tree

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 class Solution(object): ...