线程中调用service方法出错
来源:互联网 发布:新西兰特卡波星空 知乎 编辑:程序博客网 时间:2024/06/05 02:27
问题已经解决,不过还会要记录下。
public class PnFileTGIComputeThread implements Runnable { @Resource private AppUsedService appUsedService;// AppUsedService appUsedService = (AppUsedService) AllBean.getBean("appUsedService"); public String taskId; public int cityId; public PnFileTGIComputeThread(String name, int cityId){ this.taskId = name; this.cityId = cityId; } @Override public void run() { try { this.appUsedService.doSaveAzTaskAppUsedInfoCity(Integer.valueOf(taskId),cityId); } catch (Exception e){ e.printStackTrace(); } }}新建了一个线程,然后再主线程中去实例化本线程,启动线程。DUG问题是,线程启动后,参数也都传过来了,但是通过注解来注入的service一直是null值。
老办法,翻了度娘的牌子,找到问题,在线程中为了线程安全,是防注入。没办法,要用到这个类啊。只能从bean工厂里拿个实例了
public class AllBean implements ApplicationContextAware{ private static ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext context) { AllBean.applicationContext = context; } public static Object getBean(String name){ return applicationContext.getBean(name); } public static ApplicationContext getApplicationContext() { return applicationContext; } }getbean方法,获取上下文中的bean, 不过呢要有点问题,这个AllBean类需要在在Bean工厂中注册下
<bean id="allBean" class="xxxxx.AllBean" />想要啥东西,现在都可以直接去getBean,例如:
AppUsedService appUsedService = (AppUsedService) AllBean.getBean("appUsedService");
好的,线程正常启动了。 阅读全文
0 0
- 线程中调用service方法出错
- 新线程中调用service里update方法阻塞问题
- C# 线程中调用控件出错
- vs2005中web service的调用方法
- 在main方法中调用service
- Spring中利用反射调用service方法
- 混合调用Service(Service既能后台长期运行,又能调用Service中方法)
- js调用flex中as方法出错的解决办法
- 自定义Dialog 中setView方法多次调用出错
- 调用Service中的方法
- 在Activity中调用本地服务(Service)中的方法
- java的main方法中调用spring的service
- springMVC中普通类调用注解service方法
- 在Activity中调用本地服务(Service)中的方法
- 如何在jsp中调用service层的方法
- activity调用service中方法的几种方案
- android五中方式调用服务service中的方法
- 其他组件通过Binder直接调用Service中方法
- 圈圈套圈圈(3)
- ini操作
- Java进阶(八)内部类的浅析
- yum安装软件时报错libmysqlclient.so.18()(64bit)---Linux报错
- CSS 3基础样式
- 线程中调用service方法出错
- Vue——Slot(插槽)
- 使用servlet进行反射跳转
- 虚拟机(Vm12)+CentOS-7-x86_64-Minimal-1708 NAT模式 SecureCRT
- 公务员年度考核登记表
- 欢迎使用CSDN-markdown编辑器
- 获取当前工作目录
- 201709301525->untiy中打印导入资源
- boost库编译