首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

服务启动时处置业务,获取Spring Bean

2012-10-17 
服务启动时处理业务,获取Spring Bean在Web.xml添加Listenerpublic class ServerStartListener implements

服务启动时处理业务,获取Spring Bean

在Web.xml添加Listener

public class ServerStartListener implements ServletContextListener {private ConsultantService consultantService;private UserService userService;@Overridepublic void contextInitialized(ServletContextEvent sce) {ApplicationContext ac = null;ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());setUserService((UserService) ac.getBean("userService"));setConsultantService((ConsultantService) ac.getBean("consultantService"));try {getUserService().updateAllUserStatus(EnumConsultStatus.OFFLINE);Thread.sleep(2000);getConsultantService().updateAllConsultantStatus(EnumConsultStatus.OFFLINE);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}@Overridepublic void contextDestroyed(ServletContextEvent sce) {// TODO Auto-generated method stub}public ConsultantService getConsultantService() {return consultantService;}public void setConsultantService(ConsultantService consultantService) {this.consultantService = consultantService;}public UserService getUserService() {return userService;}public void setUserService(UserService userService) {this.userService = userService;}
?

热点排行