首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

监听器Listener中运用Spring创建的bean

2012-11-10 
监听器Listener中使用Spring创建的beanpackage com.dxcollector.spiderimport java.util.Timerimport ja

监听器Listener中使用Spring创建的bean

package com.dxcollector.spider;import java.util.Timer;import javax.servlet.ServletContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import org.springframework.web.context.WebApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;/** * 任务监听器 *  * @author 忧里修斯 * */public class TaskListener implements ServletContextListener {public void contextDestroyed(ServletContextEvent context) {}public void contextInitialized(ServletContextEvent context) {ServletContext servletContext = context.getServletContext();WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);SheduleTask sheduleTask = (SheduleTask) wac.getBean("sheduleTask");Timer timer = new Timer();//每隔30分钟执行一次//timer.schedule(new SheduleTask(), 0,1000*60*30);timer.schedule(sheduleTask, 0,1000*60*30);}}

热点排行