Apache commons-configuration setDelimiterParsingDisable不生效的处理
Apache commons-configuration setDelimiterParsingDisable不生效的处理
项目中有用到commons-configuration,版本1.9。
配置初始化大概这样:
CombinedConfiguration config = new CombinedConfiguration();
PropertiesConfiguration propConfig = new PropertiesConfiguration("filename...");
config.append(propConfig);
....
String value = config.getString("test.key");
在属性配置文件(×.properties)中,如下设置:
test.key=value1,value2
经调用发现value的值为"value1",通过查看源码发现,在PropertiesConfiguration中有个delimiterParsingDisable属性,它来判禁是否用自动解析List的标志,默认是解析的。当getString的时候,会取list的第一个元素。所以可以解释了为什么只获取到了value1。知道为什么了,解决办法就有了,只要将delimiterParsingDisable这个属性设置为true就不会出现这种问题了。于是有了下面的代码:
CombinedConfiguration config = new CombinedConfiguration();
PropertiesConfiguration propConfig = new PropertiesConfiguration("filename...");
propConfig.setDelimiterParsingDisable(true);
config.append(propConfig);
再次测试,发现依然不起作用,于是debug代码,发现当调用这一步的时候new PropertiesConfiguration("filename...");内部已经完成了加载,也就是说,再设置这个值是没有意义的。于是有了最终的解决办法,就是在加载数据之前,将delimiterParsingDisable这个属性设置为true。最终代码如下:
private static class PropertiesConfigurationWrapper extends PropertiesConfiguration {
public PropertiesConfigurationWrapper(String fileName) throws ConfigurationException {
super();
super.setDelimiterParsingDisabled(true); // 设置不解析list
super.setFileName(fileName);
super.load(); // 此处为加载数据的地方
}
}
Apache commons-configuration setDelimiterParsingDisable不生效的处理的更多相关文章
- 使用Apache Commons Configuration读取配置信息
在项目中使用一些比较新的库总会给你带来很多快乐,在这篇文章中,我将会给你介绍一个在Java中读取配置文件的框架——Apache Commons Configuration framework. 你会了 ...
- Apache Commons Configuration读取xml配置
近期项目自己手写一个字符串连接池.因为环境不同有开发版本.测试版本.上线版本.每一个版本用到的数据库也是不一样的.所以需要能灵活的切换数据库连接.当然这个用maven就解决了.Apache Commo ...
- Apache Commons Configuration的应用
Apache Commons Configuration的应用 Commons Configuration是一个java应用程序的配置管理工具.可以从properties或者xml文件中加载软件的配置 ...
- Apache Commons configuration使用入门
使用Commons Configuration可以很好的管理我们的配置文件的读写, 官网:http://commons.apache.org/configuration 需要用到commons-la ...
- commons configuration管理项目的配置文件
Commons Confifutation commons configuration可以很方便的访问配置文件和xml文件中的的内容.Commons Configuration 是为了提供对属性文件. ...
- Apache Commons 常用工具类整理
其实一直都在使用常用工具类,只是从没去整理过,今天空了把一些常用的整理一下吧 怎么使用的一看就明白,另外还有注释,最后的使用pom引入的jar包 public class ApacheCommonsT ...
- Commons Configuration之二基本特性和AbstractConfiguration
Configuration接口定义一大堆方法.一切从头开始实现这些方法非常困难.因为AbstractConfiguration类存在.该类在Commons Configuration中充当大多数Con ...
- Apache Commons Digester 一 (基础内容、核心API)
前言 在许多需要处理XML格式数据的应用环境中, 如果能够以“事件驱动”的方式来处理XML文档,比如,当识别出特定的XML元素时,触发“创建对象”操作事件(或者触发调用对象的方法事件),这对于应用程序 ...
- Apache Commons CLI命令行启动
今天又看了下Hangout的源码,一般来说一个开源项目有好几种启动方式--比如可以从命令行启动,也可以从web端启动.今天就看看如何设计命令行启动... Apache Commons CLI Apac ...
随机推荐
- java util 下的concurrent包
------------------------------------------java util 下的concurrent包--------并发包--------------------.jav ...
- 解读ASP.NET 5 & MVC6系列(14):View Component
在之前的MVC中,我们经常需要类似一种小部件的功能,通常我们都是使用Partial View来实现,因为MVC中没有类似Web Forms中的WebControl的功能.但在MVC6中,这一功能得到了 ...
- [LeetCode] Course Schedule 课程清单
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- css的字体
移动端使用的字体:http://www.cnblogs.com/PeunZhang/p/3592096.html
- sql server 中隐藏掉无关数据库
先贴上我实际测试的效果 方法一: Problem I have a SQL Server instance that has hundreds of databases. Navigating th ...
- rank()函数的使用
排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...
- 数据可视化 echarts3
初识 echarts ECharts,一个纯 Javascript 的数据可视化图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefo ...
- Python安装pywinauto时遇到error: The read operation timed out解决方法
Python结合Pywinauto 进行 Windows UI 自动化,安装pywinauto时遇到的一些问题: 解决方法:很明显是链接超时国外网站你懂的V_P_N吧,直接通过报错信息的链接复制到浏览 ...
- 小猪cms微信二次开发之怎样分页
$db=D('Classify'); $zid=$db->where(array('id'=>$this->_GET('fid'),'token'=>$this->tok ...
- js控制Bootstrap 模态框(Modal)插件
js控制Bootstrap 模态框(Modal)插件 http://www.cnblogs.com/zzjeny/p/5564400.html