自定义监听器中的属性注入问题
2015-06-04 16:54
330 查看
由于好久没有用过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();
}
解决的办法是
加 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();
}
写下来免得以后再忘记
相关文章推荐
- Java实现新浪微博模拟登陆
- SpringMVC 学习笔记(七) JSON返回:HttpMessageConverter作用
- JS数组的常用方法总结
- sql ntext数据类型怎么查询
- 运算符实例/数据类型真假
- Python命令tab键自动补全
- linux安装mongodb
- 警惕被传统企业拖死!那些年轻人不该走的弯
- 套接字 中 shutdown与close区别
- 移动端如何准确获取页面的宽度
- maven 编译
- MVC4 WebAPI(二)——Web API工作方式
- LeetCode: Valid Palindrome [125]
- 缩放浏览器时 背景图片固定
- 百度地图之定位
- Spring Cache抽象详解
- 新浪微博自动(模拟)登陆详解及实现
- HDU 3629 图的同构
- npm仓库操作
- windows find 文件