首页>代码>SSH框架+Mysql数据库开发java web会员积分消费管理系统>/DM/vipManage/src/com/nd/listener/ProxoolListener.java
package com.nd.listener;

import java.io.File;
import java.util.Enumeration;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;

/**
 * @author wangtao
 */

public class ProxoolListener implements ServletContextListener
{
	private static final Log LOG = LogFactory.getLog(ProxoolListener.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";
    
    @SuppressWarnings("unused")
	private boolean autoShutdown = true;
	
    public void contextDestroyed(ServletContextEvent arg0)
	{
		System.out.println("destroy database pool....");
	}

	@SuppressWarnings("rawtypes")
	public void contextInitialized(ServletContextEvent contextEvent)
	{
		ServletContext context = contextEvent.getServletContext(); //对应servlet的init方法中ServletConfig.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")) { //此处以前是PropertyConfigurator.PREFIX改为jdbc,因为此源码是0.9.1版本的,与0.9RC3版本有点不一样
                properties.setProperty(name, value);
            }
        }

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

}
最近下载更多
xp95323  LV14 2023年10月30日
是夜在熬我.  LV6 2022年11月30日
1641426181  LV4 2022年11月9日
testuser1234567  LV24 2022年7月21日
2716804680  LV9 2022年7月16日
zhaoyangwfd  LV17 2022年6月16日
ming_123_9715  LV23 2022年6月8日
wsgwly  LV5 2022年6月6日
远程调试_成品系统  LV15 2022年5月30日
双方各何必呢  LV13 2022年5月14日
最近浏览更多
wz  LV3 4月24日
WBelong  LV7 2023年12月27日
穿山甲1001  LV4 2023年12月16日
Henew168  LV2 2023年11月19日
森sdfgf  LV8 2023年10月21日
2036495585  LV9 2023年9月25日
wbx666  LV1 2023年9月25日
15575564465  LV1 2023年9月14日
527301883  LV1 2023年9月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友