读书人

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

发布时间: 2012-10-17 10:25:46 作者: rapoo

服务启动时处理业务,获取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;}
?

读书人网 >开源软件

热点推荐