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