简单的读取配置文件的工具类

import java.util.HashMap;

import java.util.Map;

import java.util.Properties;

import org.springframework.beans.BeansException;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

 

public class PropertiesUtil

  extends PropertyPlaceholderConfigurer

{

  private static Map<String, Object> ctxPropertiesMap = new HashMap();

  

  protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)

    throws BeansException

  {

    super.processProperties(beanFactoryToProcess, props);

    for (Object key : props.keySet())

    {

      String keyStr = key.toString();

      String value = props.getProperty(keyStr);

      ctxPropertiesMap.put(keyStr, value);

    }

  }

  

  public static Object getContextProperty(String name)

  {

    return ctxPropertiesMap.get(name);

  }

  

  public static String getContexrtParam(String name)

  {

    return (String)ctxPropertiesMap.get(name);

  }

  

  public static void load(Map map)

  {

    if ((map != null) && (!map.isEmpty())) {

      for (Object key : map.keySet()) {

        ctxPropertiesMap.put(key.toString(), map.get(key));

      }

    }

  }

}

原文地址:https://www.cnblogs.com/tom-plus/p/7581439.html