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); } } }
相关文章推荐
- web.xml文件中引用log4J的配置以及log4J文件配置
- Struts2控制器以及struts.xml与web.xml的配置(1)
- log4j slf4j 以及web.xml日志配置
- Spring整合Hibernate的XML文件配置,以及web.xml文件配置
- 如何在web.xml配置spring,struts2配置以及过滤器
- struts2整合spring 时web.xml的配置
- SSH框架整合的时候 在web.xml中需配置的spring信息与struts2的配置信息
- 怎么在web.xml配置spring,struts2配置以及过滤器
- Struts2 + Spring + Hibernate 整合 web.xml的一般配置
- struts2与spring整合web.xml加入的配置
- spring整合struts2之web.xml配置
- web.xml文件中引用log4J的配置以及log4J文件配置
- Struts在Web.xml中的配置及Struts1和Struts2的区别
- 使用Struts1.x 与 struts2.x下的web.xml的配置
- Struts2配置文件复用代码【web.xml、struts.xml、常量配置】
- struts2标签应用 需在web.xml中 配置
- struts-2.3.31和struts-2.5.10引入jar以及配置web.xml和struts.xml
- jboss下通过配置log4j.xml实现web应用的日志
- tomcat WEB.XML 配置(struts2)
- web.xml中log4j配置注意点