您的位置:首页 > 编程语言 > Java开发

web.xml包含struts2整合spring3以及配置log4j和数据连接池

2011-11-02 11:05 417 查看
ProxoolInitListener

public class ProxoolInitListener implements ServletContextListener {
private static final Log LOG = LogFactory.getLog(ProxoolInitListener.class);

private static final String XML_FILE_PROPERTY = "xmlFile";

private static final String PROPERTY_FILE_PROPERTY = "propertyFile";

private static final String AUTO_SHUTDOWN_PROPERTY = "autoShutdown";

private boolean autoShutdown = true;

public void contextInitialized(ServletContextEvent contextEvent) {
ServletContext context = contextEvent.getServletContext();

String appDir = contextEvent.getServletContext().getRealPath("/");

Properties properties = new Properties();

Enumeration names = context.getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String value = context.getInitParameter(name);

if (name.equals(XML_FILE_PROPERTY)) {
try {
File file = new File(value);
if (file.isAbsolute()) {
JAXPConfigurator.configure(value, false);
} else {
JAXPConfigurator.configure(appDir + File.separator
+ value, false);
}
} catch (ProxoolException e) {
LOG.error("Problem configuring " + value, e);
}
} else if (name.equals(PROPERTY_FILE_PROPERTY)) {
try {
File file = new File(value);
if (file.isAbsolute()) {
PropertyConfigurator.configure(value);
} else {
PropertyConfigurator.configure(appDir + File.separator
+ value);
}
} catch (ProxoolException e) {
LOG.error("Problem configuring " + value, e);
}
} else if (name.equals(AUTO_SHUTDOWN_PROPERTY)) {
autoShutdown = Boolean.valueOf(value).booleanValue();
} else if (name.startsWith("jdbc")) {// 这里原来不是jdbc,用原来的报错,这里是说在找properties文件时,找以jdbc开头的,这里用的xml文件,所以这里无所谓
properties.setProperty(name, value);
}
}

if (properties.size() > 0) {
try {
PropertyConfigurator.configure(properties);
} catch (ProxoolException e) {
LOG.error("Problem configuring using init properties", e);
}
}
}

public void contextDestroyed(ServletContextEvent contextEvent) {
if (autoShutdown) {
ProxoolFacade.shutdown(0);
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: