1. 程式人生 > >簡單的讀取配置文件的工具類

簡單的讀取配置文件的工具類

rtp get param set style lin 8.0 top app

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));

}

}

}

}

簡單的讀取配置文件的工具類