在用多线程的时候,里面要用到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 多线程 注入 服务层 问题的更多相关文章

  1. 为什么多线程、junit 中无法使用spring 依赖注入?

    为什么多线程.junit 中无法使用spring 依赖注入? 这个问题,其实体现了,我们对spring已依赖太深,以至于不想自己写实例了. 那么到底是为什么在多线程和junit单元测试中不能使用依赖注 ...

  2. spring多线程与定时任务

    本篇主要描述一下spring的多线程的使用与定时任务的使用. 1.spring多线程任务的使用 spring通过任务执行器TaskExecutor来实现多线程与并发编程.通常使用ThreadPoolT ...

  3. Spring自动注入properties文件

    实现spring 自动注入属性文件中的key-value. 1.在applicationContext.xml配置文件中,引入<util />命名空间. xmlns:util=" ...

  4. spring 属性注入

    Spring的核心技术室依赖注入,下面是依赖注入之属性注入的实现过程,牛刀小试,请看效果. 1.首先添加Spring.Web引用.本例中是使用分层思想来演示的,下面是项目的结构和UserModel类的 ...

  5. Spring 依赖注入方式详解

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法. 通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由 ...

  6. Spring的注入问题

    作下笔记,Spring的注入问题[多个实例问题] 解决方案如下: package student.life.support.platform.service.impl; import javax.an ...

  7. Spring依赖注入(IOC)那些事

    小菜使用Spring有几个月了,但是对于它的内部原理,却是一头雾水,这次借着工作中遇到的一个小问题,来总结一下Spring. Spring依赖注入的思想,就是把对象交由Spring容器管理,使用者只需 ...

  8. Spring依赖注入三种方式详解

    在讲解Spring依赖注入之前的准备工作: 下载包含Spring的工具jar包的压缩包 解压缩下载下来的Spring压缩包文件 解压缩之后我们会看到libs文件夹下有许多jar包,而我们只需要其中的c ...

  9. Spring依赖注入:注解注入总结

    更多11   spring   依赖注入   注解   java 注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解有Autowired.Resource.Qualifier.S ...

随机推荐

  1. cache-contro页面缓存处理设置

    <meta http-equiv="pragma" content="no-cache">,pragma与no-cache用于定义页面缓存,不缓存页 ...

  2. 第三次作业:caculator

    第三次作业 作业链接 ********* 遇到的问题: Scan类: 队列的使用方法不了解,上网查询并自己练习了一下才初步了解,才运用到作业 . 判断数字用的 if (input[i] >= ' ...

  3. Windows转到linux中,文件乱码,文件编码转换 & 解决sqlplus连接oracle乱码

    转载:http://www.cnblogs.com/wanyao/p/3399269.html 最近,学习又重新开始Linux学习,所以一直在Centos中,昨天一朋友把他在Windows下写的C程序 ...

  4. delphi 类方法、类变量、类常量、类属性的研究,自己的研究

    群里我师傅给我的答案: unit Unit4; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Vari ...

  5. Python语法二

    1.raw_input 输入 2.如果想查看某个关键字的用法,可以在命令行输入pydoc raw_input. 如果是windows,那么试一下 python -m pydoc raw_input 3 ...

  6. 【转】 C# 小技巧之获取变量名称

    link: http://www.cnblogs.com/gongy/p/lm-2015-04-03.html 今天在自我规范程序设计的时候,变量名匹配字符串来自配置文件,网上找了一会儿发现也有朋友在 ...

  7. 问题1:Mybatis 中 Signature中的参数args 问题2:MetaObject中 forObject方法中的参数

    1.@Intercepts({@Signature(type =StatementHandler.class, method = "prepare", args ={Connect ...

  8. c++ c# java 调用 c++ 写的dll

    1. vs 中新建win32 dll 项目   testdll 添加实现文件       test.cpp #include "stdafx.h" #include <ios ...

  9. javascript照片墙效果

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. Java和.NET使用DES对称加密的区别

    Java和.NET的系统类库里都有封装DES对称加密的实现方式,但是对外暴露的接口却各不相同,甚至有时会让自己难以解决其中的问题,比如Java加密后的结果在.NET中解密不出来等,由于最近项目有跨Ja ...