Apache Commons Configuration的应用
Commons Configuration是一个java应用程序的配置管理工具。可以从properties或者xml文件中加载软件的配置信息,用来构建支撑软件运行的基础环境。在一些配置文件较多较的复杂的情况下,使用该配置工具比较可以简化配置文件的解析和管理。也提高了开发效率和软件的可维护性。
一、介绍
官方列举Commons Configuration的主要功能:
Configuration parameters may be loaded from the following sources:
Properties files 
XML documents 
Windows INI files 
Property list files (plist) 
JNDI 
JDBC Datasource 
System properties 
Applet parameters 
Servlet parameters
Commons Configuration所依赖的包
Component Dependencies
Core Java 1.3
commons-collections
commons-lang
commons-logging
ConfigurationFactory commons-digester
commons-beanutils
Java 1.4 or xml-apis
DefaultConfigurationBuilder commons-beanutils
Java 1.4 or (xml-apis + xerces + xalan)
DatabaseConfiguration JDBC 3.0 (Java 1.4 or jdbc2_0-stdext.jar)
XMLConfiguration Java 1.4 or (xml-apis + xerces + xalan)
XMLPropertiesConfiguration Java 1.4 or (xml-apis + xerces)
PropertyListConfiguration commons-codec
XMLPropertyListConfiguration commons-codec
Java 1.4 or xml-apis
ConfigurationDynaBean commons-beanutils
XPathExpressionEngine commons-jxpath
EnvironmentConfiguration Java 1.5 or ant 1.6.5
 
二、给出一个简单的例子
 
package cfgtest;

import org.apache.commons.configuration.*;

/** 
* Commons Configuration读取属性文件的例子 

* @author leizhimin 2008-9-23 9:40:17 
*/ 
public class Test1 { 
        public static void main(String[] args) throws ConfigurationException { 
                test1(); 
        }

public static void test1() throws ConfigurationException { 
                 
                CompositeConfiguration config = new CompositeConfiguration(); 
                //config.addConfiguration(new SystemConfiguration()); 
                config.addConfiguration(new PropertiesConfiguration("cfgtest/test1.properties")); 
                 
                String usernaem = config.getString("username"); 
                String password = config.getString("password"); 
                 
                System.out.println(usernaem + " " + password);


}

 
cfgtest/test1.properties
username = lavasoft 
password = leizhimin 
 
运行结果:
lavasoft leizhimin

Process finished with exit code 0

 
从上面看出,使用Apache Commons Configuration来读取配置确实很简单,还可以省很多事情。它不光可以读取properties文件,还可以读取xml,还可以读取xml和properties混合文件等等。

Apache Commons Configuration的应用的更多相关文章

  1. 使用Apache Commons Configuration读取配置信息

    在项目中使用一些比较新的库总会给你带来很多快乐,在这篇文章中,我将会给你介绍一个在Java中读取配置文件的框架——Apache Commons Configuration framework. 你会了 ...

  2. Apache Commons Configuration读取xml配置

    近期项目自己手写一个字符串连接池.因为环境不同有开发版本.测试版本.上线版本.每一个版本用到的数据库也是不一样的.所以需要能灵活的切换数据库连接.当然这个用maven就解决了.Apache Commo ...

  3. Apache Commons configuration使用入门

    使用Commons  Configuration可以很好的管理我们的配置文件的读写, 官网:http://commons.apache.org/configuration 需要用到commons-la ...

  4. commons configuration管理项目的配置文件

    Commons Confifutation commons configuration可以很方便的访问配置文件和xml文件中的的内容.Commons Configuration 是为了提供对属性文件. ...

  5. Apache Commons 常用工具类整理

    其实一直都在使用常用工具类,只是从没去整理过,今天空了把一些常用的整理一下吧 怎么使用的一看就明白,另外还有注释,最后的使用pom引入的jar包 public class ApacheCommonsT ...

  6. Commons Configuration之二基本特性和AbstractConfiguration

    Configuration接口定义一大堆方法.一切从头开始实现这些方法非常困难.因为AbstractConfiguration类存在.该类在Commons Configuration中充当大多数Con ...

  7. Apache Commons CLI命令行启动

    今天又看了下Hangout的源码,一般来说一个开源项目有好几种启动方式--比如可以从命令行启动,也可以从web端启动.今天就看看如何设计命令行启动... Apache Commons CLI Apac ...

  8. 编写更少量的代码:使用apache commons工具类库

    Commons-configuration   Commons-FileUpload   Commons DbUtils   Commons BeanUtils  Commons CLI  Commo ...

  9. Apache Commons 工具集

    一.Commons BeanUtils http://jakarta.apache.org/commons/beanutils/index.html 说明:针对Bean的一个工具集.由于Bean往往是 ...

随机推荐

  1. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  2. Git的使用方法与GitHub项目托管方法

    Git的安装 Windows上安装Git 访问网址:https://git-for-windows.github.io/ 点击Download下载,下载后双击安装包进行安装,一直"下一步&q ...

  3. 记录下java的个人测试方法

    IDEA,用 JUnitGenerator V2.​ 0 做单元测试.. 如果是 SpringBoot,测试类上面加注解 @RunWith(SpringJUnit4ClassRunner.class) ...

  4. 【BZOJ 3233】 [Ahoi2013]找硬币

    [题目 描述] 小蛇是金融部部长. 最近她决定制造一系列新的货币. 假设她要制造的货币 的面值为 x1, x2, x3… 那么 x1 必须为 1, xb 必须为 xa 的正整数倍(b>a). 例 ...

  5. ZOJ1221 Risk

    Description Risk is a board game in which several opposing players attempt to conquer the world. The ...

  6. 应用日志获取-web系统

    1 场景 应用使开发写的,但应用使部署再服务器上,而开发没有ssh登陆服务器的权限. so,开发总是请运维查日志,下载日志. so and so,运维要花很多时间帮开发去搞日志. 这是件很没意义的事, ...

  7. python 基础(十四) 正则表达式

    正则表达式 概念: 正则匹配就是一个模糊的匹配 只要符合我的匹配规则 就会认为是正确的数据(精确的匹配) 1.[] #代表原子表把想要匹配的内容写入原子表中   匹配包含的任意一位字符 [a]     ...

  8. RTT

    Segger RTT的使用 一般arm系统中,如何通过电脑键盘和显示器同mcu进行交互最有效的有两种形式:arm7的semihost,cm时代的traceswo.现在jlink推出了颇具特色的rtt( ...

  9. Unity Shader入门精要学习笔记 - 第8章 透明效果

    转载自 冯乐乐的 <Unity Shader入门精要> 透明是游戏中经常要使用的一种效果.在实时渲染中要实现透明效果,通常会在渲染模型时控制它的透明通道.当开启透明混合后,当一个物体被渲染 ...

  10. 一图秒懂http与https的区别

    HTTPS与HTTP的一些区别 HTTPS协议需要到CA申请证书,一般免费证书很少,需要交费. HTTP协议运行在TCP之上,所有传输的内容都是明文,HTTPS运行在SSL/TLS之上,SSL/TLS ...