自定义监听器中的属性注入问题

来源:互联网 发布:哈尔滨软件培训学校 编辑:程序博客网 时间:2024/05/17 14:19

 由于好久没有用过spring 最近写一个自定义监听器 中的service 属性注入问题 一直注入不进去值 原来是ServletContextListener 跟spring 一起启动的 注入不进去

解决的办法是

 加  private WebApplicationContext springContext; 

public void contextInitialized(ServletContextEvent event) { springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());  if(springContext != null){  ordersService = (OrdersService)springContext.getBean("ordersService");  subscriberService = (SubscriberService)springContext.getBean("subscriberService");  carGroupService = (CarGroupService)springContext.getBean("carGroupService");  }else{   System.out.println("获取应用程序上下文失败!");   return;  }  System.out.println("初始化系统服务!"); Th1 th1 = new Th1(); th1.start();}
写下来免得以后再忘记

0 0
原创粉丝点击