spring 多线程 注入 服务层 问题
在用多线程的时候,里面要用到Spring注入服务层,或者是逻辑层的时候,一般是注入不进去的。具体原因应该是线程启动时没有用到Spring实例不池。所以注入的变量值都为null。
详细:http://hi.baidu.com/adrianbutler/item/800218d90f23b0e53dc2cb95
因为我用的是@Autowired注入,不知道为什么 解决不了我的问题,继续查找资料,好在柳暗花明
详细: http://blog.csdn.net/majian_1987/article/details/8157668
采用楼主所说的方法,我用的是springMVC
在Controller中创建Thread的时候把Controller中的service引用作为构造参数传递给Thread,这样Thread中的Service对象就是通过SPring的自动注入得到的了。
这是实现 线程的时候 ImStuThread.java ,哈哈,引用注入有点多啊
private IDepartmentService departmentService;
private IUserService userService;
private IMajorService majorService;
private IClassxService classxService;
private IGradeService gradeService;
private String user; public ImStuThread(IDepartmentService departmentService,IUserService userService,IMajorService majorService,
IClassxService classxService,IGradeService gradeService,String user){
this.departmentService = departmentService;
this.userService = userService;
this.majorService = majorService;
this.classxService = classxService;
this.gradeService = gradeService;
this.user = user;
}
在 Controller 中就可以这样实现了
ImStuThread imStuThread = new ImStuThread(departmentService,userService,majorService,classxService,gradeService,user);
这样就可以解决 spring 多线程 注入 服务层 问题 了,恩恩,至少我的解决了!
spring 多线程 注入 服务层 问题的更多相关文章
- 为什么多线程、junit 中无法使用spring 依赖注入?
为什么多线程.junit 中无法使用spring 依赖注入? 这个问题,其实体现了,我们对spring已依赖太深,以至于不想自己写实例了. 那么到底是为什么在多线程和junit单元测试中不能使用依赖注 ...
- spring多线程与定时任务
本篇主要描述一下spring的多线程的使用与定时任务的使用. 1.spring多线程任务的使用 spring通过任务执行器TaskExecutor来实现多线程与并发编程.通常使用ThreadPoolT ...
- Spring自动注入properties文件
实现spring 自动注入属性文件中的key-value. 1.在applicationContext.xml配置文件中,引入<util />命名空间. xmlns:util=" ...
- spring 属性注入
Spring的核心技术室依赖注入,下面是依赖注入之属性注入的实现过程,牛刀小试,请看效果. 1.首先添加Spring.Web引用.本例中是使用分层思想来演示的,下面是项目的结构和UserModel类的 ...
- Spring 依赖注入方式详解
平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...
- Spring的注入问题
作下笔记,Spring的注入问题[多个实例问题] 解决方案如下: package student.life.support.platform.service.impl; import javax.an ...
- Spring依赖注入(IOC)那些事
小菜使用Spring有几个月了,但是对于它的内部原理,却是一头雾水,这次借着工作中遇到的一个小问题,来总结一下Spring. Spring依赖注入的思想,就是把对象交由Spring容器管理,使用者只需 ...
- Spring依赖注入三种方式详解
在讲解Spring依赖注入之前的准备工作: 下载包含Spring的工具jar包的压缩包 解压缩下载下来的Spring压缩包文件 解压缩之后我们会看到libs文件夹下有许多jar包,而我们只需要其中的c ...
- Spring依赖注入:注解注入总结
更多11 spring 依赖注入 注解 java 注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解有Autowired.Resource.Qualifier.S ...
随机推荐
- Cordova 打包 Android release app 过程详解
Cordova 打包 Android release app 过程详解 时间 -- :: SegmentFault 原文 https://segmentfault.com/a/119000000517 ...
- 头像上传,拖拽,裁切 (非HTML5)版本
演示地址: http://codeman35.itongyin.com:19002/v2/web_demo.html 功能: 支持滚轴放大缩小,鼠标拖动,裁切可视区域,裁切和图片处理都是后端操作.
- Google Protocol Buffer 的使用
简介 Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 ...
- log4net的各种Appender配置示例
Apache log4net™ Config Examples Overview This document presents example configurations for the built ...
- Android使用ViewPager做轮播
ViewPager.html div.oembedall-githubrepos { border: 1px solid #DDD; list-style-type: none; margin: 0 ...
- ruby 简介
Ruby 是一个注重均衡的语言,它的发明者松本行弘 Yukihiro “Matz” Matsumoto,混合了他喜欢的语言(Perl. Smalltalk. Eiffel. Ada 和 Lisp ) ...
- IOS--UIAlertView造成屏幕闪烁
在异步操作中,如果直接Show一个UIAlertView可能会造成屏幕闪烁(目前在iPhone5上发现),解决办法如下: UIAlertView *alert = [[UIAlertView allo ...
- 用Docker Compose启动Nginx和Web等多个镜像
安装docker-compose 运行命令 curl -L "https://github.com/docker/compose/releases/download/1.9.0/docker ...
- centos7.2下编译安装&&使用-git代码库
centos7.2下编译安装git Git简介 Git是一个分布式版本控制系统 Git vs SVN SVN是典型的集中式版本控制起,版本库集中存放在服务器,当我们用自己的电脑干活儿的时候,需要先从中 ...
- fiddler抓取Android 真机app数据包
fiddler功能强大 不仅能抓pc上的请求还能抓取手机上的请求.下面以fiddler4 +android手机为例介绍一下 手机抓包. 官网下载fiddler后下一步下一步安装成功. 首先是fiddl ...