autoconfig这种机制在软件开发和发布的过程中是非常方便也是非常必要的一种动态替换配置信息的一种手段,一种很贴切的比喻:这个就像在windows下面安装一个软件时,我们按照安装向导给我们弹出提示填写信息一样(这些信息就是一些定制化的信息)。

Maven的强大插件机制,可以和autoconfig机制结合起来,发挥巨大的威力。

实际项目中,基本都是在deploy下面实现配置文件的读取和替换的。这里,其实就是利用了一个maven-autoconf-plugin插件实现的这个功能。具体deploy下面pom.xml的配置片段如下:

  1. <profiles>
  2. <!-- Dev profile will configure all files and copy them to target/dev, for testing purpose -->
  3. <profile>
  4. <id>dev</id>
  5. <activation>
  6. <property>
  7. <name>env</name>
  8. <value>!release</value>
  9. </property>
  10. </activation>
  11. <build>
  12. <plugins>
  13. <!-- do auto config for integration test -->
  14. <plugin>
  15. <groupId>com.alibaba.maven.plugins</groupId>
  16. <artifactId>maven-autoconf-plugin</artifactId>
  17. <version>0.3-alpha-9</version>
  18. <executions>
  19. <execution>
  20. <phase>pre-integration-test</phase>
  21. <goals>
  22. <goal>config</goal>
  23. </goals>
  24. </execution>
  25. </executions>
  26. <configuration>
  27. <destFiles>
  28. <destFile>${project.basedir}</destFile>
  29. </destFiles>
  30. <includeDescriptorPatterns>
  31. <!-- intl-site flavor -->
  32. <includeDescriptorPattern>autoconf/auto-config.xml</includeDescriptorPattern>
  33. <!-- china-site flavor -->
  34. <includeDescriptorPattern>conf/META-INF/autoconf/auto-config.xml</includeDescriptorPattern>
  35. </includeDescriptorPatterns>
  36. <includePackagePatterns>
  37. <includePackagePattern>**/*.war</includePackagePattern>
  38. </includePackagePatterns>
  39. </configuration>
  40. </plugin>
  41. </plugins>
  42. </build>
  43. </profile>
  44. </profiles>

这里,又一次应用了COC的思想,插件会去扫描autoconf/auto-config.xml或者conf/META-INF/autoconf/auto-config.xml。

目前这个插件还比较鸡肋,不过基本功能都是有的,详细的介绍,可以直接参考他的官方介绍:http://repo.alibaba-inc.com/mvn/internal/snapshots/sites/maven-autoconf-plugin/config-mojo.html

常用的几个属性列举如下:

  • includeDescriptorPatterns:autoconfig所要扫描的描述文件的匹配路径。
  • userProp:指定用户实际使用配置信息的配置文件的路径,如:-DuserProp=/home/abc/properties.txt

本文来自于:http://hittyt.iteye.com/blog/889158

最新文章

  1. CoreProfiler/NanoProfiler性能调试监控系列总目录
  2. 机器学习之KNN算法思想及其实现
  3. 【poj2741】 Colored Cubes
  4. 从出租车司机到大BOSS的转型之路
  5. 夺命雷公狗ThinkPHP项目之----企业网站16之文章批量删除的完成
  6. plupload上传控件错误exec(this.uid, component, action, args)
  7. 【转】android应用程序签名
  8. javascript显示倒计时控制按钮
  9. 如何定时备份远程mysql数据库
  10. poj 3608 旋转卡壳求不相交凸包最近距离;
  11. c 查找A字符串在B字符串中是否存在,计算出现的次数
  12. .Net 文本框实现内容提示(仿Google、Baidu)
  13. AR9331中Linux内核启动中与IRQ中断相关的文件
  14. 机器学习 —— 基础整理(六)线性判别函数:感知器、松弛算法、Ho-Kashyap算法
  15. form表单中enctype属性作用
  16. org.json.JSONObject的optXXX方法
  17. ajaj简介
  18. Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列)
  19. k8s1.13.3安装istio(helm方式)
  20. ECharts中color : function的用法(转)

热门文章

  1. iOS开发——UI篇OC篇&amp;不规则排列的图片布局
  2. sphinx配置文件继承
  3. pip和easy_install使用方式
  4. (转)如何在JavaScript与ActiveX之间传递数据3
  5. 读写锁ReaderWriterLockSlim
  6. java_可变参数构造器 Bulder模式
  7. IIS 之 查看并发连接数
  8. Android_Intent_passValue(4)
  9. [转]Oracle学习笔记——权限管理
  10. 使用kdbg或nemiver调试ROS