package com.nstars.common.web.listener;
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.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.nstars.baseobjectanalyse.service.IBaseObjectMgr;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;
/**
* 服务启动时可以做一些自定义的初始化动作
*
*
*/
public class StartupListener extends ContextLoaderListener implements ServletContextListener {
private static final Log log = LogFactory.getLog(StartupListener.class);
public void contextInitialized(ServletContextEvent event) {//系统启动时所作操作
ServletContext context = event.getServletContext();
if (log.isDebugEnabled()) {
log.debug("系统初始化开始...");
}
super.contextInitialized(event);
// ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
//ProviderManager provider = (ProviderManager) ctx.getBean("authenticationManager");//得到其service层接口
// call Spring's context ContextLoaderListener to initialize
// all the context files specified in web.xml
setupContext(context);
if (log.isDebugEnabled()) {
log.debug("系统初始化结束...");
}
}
public static void setupContext(ServletContext context) {
//其实这里可以调用任何东西
GeneralCacheAdministrator admin=new GeneralCacheAdministrator();
admin.flushAll();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
IBaseObjectMgr ibom=(IBaseObjectMgr)ctx.getBean("baseObjMgr");
admin.removeEntry("CacheForVarietyInstances");
if (log.isDebugEnabled()) {
log.debug("系统初始化实例化品种缓存开始...");
}
ibom.readVarietyInstance();
if (log.isDebugEnabled()) {
log.debug("系统初始化实例化品种缓存结束...");
}
//XXXMgr mgr = (XXXMgr) ctx.getBean("lookupManager");
// 甚至可以设置一些公用常量在里边。
//context.setAttribute(Constants.AVAILABLE_ROLES, mgr.getAllRoles());
//log.debug("Drop-down initialization complete [OK]");
}
public void contextDestroyed(ServletContextEvent event) {//系统关闭时所作操作
// TODO Auto-generated method stub
super.contextDestroyed(event);
}
}
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.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.nstars.baseobjectanalyse.service.IBaseObjectMgr;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;
/**
* 服务启动时可以做一些自定义的初始化动作
*
*
*/
public class StartupListener extends ContextLoaderListener implements ServletContextListener {
private static final Log log = LogFactory.getLog(StartupListener.class);
public void contextInitialized(ServletContextEvent event) {//系统启动时所作操作
ServletContext context = event.getServletContext();
if (log.isDebugEnabled()) {
log.debug("系统初始化开始...");
}
super.contextInitialized(event);
// ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
//ProviderManager provider = (ProviderManager) ctx.getBean("authenticationManager");//得到其service层接口
// call Spring's context ContextLoaderListener to initialize
// all the context files specified in web.xml
setupContext(context);
if (log.isDebugEnabled()) {
log.debug("系统初始化结束...");
}
}
public static void setupContext(ServletContext context) {
//其实这里可以调用任何东西
GeneralCacheAdministrator admin=new GeneralCacheAdministrator();
admin.flushAll();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
IBaseObjectMgr ibom=(IBaseObjectMgr)ctx.getBean("baseObjMgr");
admin.removeEntry("CacheForVarietyInstances");
if (log.isDebugEnabled()) {
log.debug("系统初始化实例化品种缓存开始...");
}
ibom.readVarietyInstance();
if (log.isDebugEnabled()) {
log.debug("系统初始化实例化品种缓存结束...");
}
//XXXMgr mgr = (XXXMgr) ctx.getBean("lookupManager");
// 甚至可以设置一些公用常量在里边。
//context.setAttribute(Constants.AVAILABLE_ROLES, mgr.getAllRoles());
//log.debug("Drop-down initialization complete [OK]");
}
public void contextDestroyed(ServletContextEvent event) {//系统关闭时所作操作
// TODO Auto-generated method stub
super.contextDestroyed(event);
}
}