package com.iamberry.common.web;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2016年10月18日
 * @explain	Web容器启动
 */
public class ApplicationInitListener implements ServletContextListener {

	private static Logger logger = Logger.getLogger(ApplicationInitListener.class);

	public void contextInitialized(ServletContextEvent event) {
		try {
			AbstractApplicationContext abstractApplicationContext = (AbstractApplicationContext) WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
			// 注册shutdown Hook,保证tomcat 关闭时，获取事件
			abstractApplicationContext.registerShutdownHook();
			
			logger.info("Spring 注册Shutdown Hook SUCCESS!");
		} catch (Exception e) {
			logger.error("系统初始化失败！",e);
		}
	}
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
	}
}
