首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

spring中取得属性文件键值对,在程序中使用

2012-12-26 
spring中获得属性文件键值对,在程序中使用package com.chinaGPS.nss.utilimport java.util.HashMapimpor

spring中获得属性文件键值对,在程序中使用

package com.chinaGPS.nss.util;import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Properties;import org.apache.commons.lang.StringUtils;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;import com.chinaGPS.nss.constant.SystemConst;/**加载属性类 * @author zhz * */public class MyPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {  private Map<String, String> resolvedProps;//将属性保存起来  @Override  protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,      Properties props) throws BeansException {      super.processProperties(beanFactoryToProcess, props);      resolvedProps = new HashMap<String, String>();      for (Object key : props.keySet()) {          String keyStr = key.toString();                    if(StringUtils.equals(keyStr, "auto_craw"))          {          String tmp = parseStringValue(props.getProperty(keyStr), props,new HashSet());          if(StringUtils.equalsIgnoreCase(tmp, "on"))  SystemConst.AUTOCRAW  = "on";  if(StringUtils.equalsIgnoreCase(tmp, "off"))  SystemConst.AUTOCRAW="off";  else  continue;          }//          resolvedProps.put(keyStr, parseStringValue(props.getProperty(keyStr), props,//                  new HashSet()));      }  }}

?

1 楼 yangshiman 2012-02-10   protected void processProperties(
ConfigurableListableBeanFactory beanFactoryToProcess,
Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess,props);
for (Enumeration propertyNames = props.propertyNames(); propertyNames.hasMoreElements();) {
String propertyName = (String) propertyNames.nextElement();
String propertyValue = props.getProperty(propertyName);
String convertedValue = convertProperty(propertyName, propertyValue);
PropertiesPool.load(propertyName, convertedValue);
}
}

热点排行