package com.monitor.util;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Configruation
{
private static final Log log = LogFactory.getLog("common");
private static InputStream input = null;
private static Properties props = null;
public static Properties getProperties()
{
if (props == null)
initProperties();
return props;
}
public static String getProperty(String key)
{
if (props == null)
initProperties();
return props.getProperty(key);
}
/**
* 读取应用程序的默认配置文件,并取得相关配置值
*/
private static synchronized void initProperties()
{
props = new Properties();
try
{
if (props.size() == 0) {
input = Configruation.class.getClassLoader().getResourceAsStream("application.properties");
props.load(input);
}
}
catch(Exception ex)
{
props = null;
log.error(ex.getMessage());
}
finally
{
if(input != null){
try
{
input.close();
input = null;
}
catch(Exception ex)
{
log.warn("close the application properties input stream failed:" + ex.getMessage());
}
}
}
}
}
配置文件Configuration工具类
最新推荐文章于 2024-05-23 21:48:00 发布