异常-----spring明明注入了Service到Action中,为什么运行的时候Service为空,在抽象类中,有子类来继承的
xml的配置文件
<bean id="fftController" class="com.bill99.query.controller.FftController" abstract="true">
<property name="wxOrderService" ref="wxOrderService" />
</bean>
<bean id="wxFFanController1" class="com.bill99.query.controller.WXFFanController1" parent="fftController">
<property name="methodNameResolver">
<ref bean="paramResolver" />
</property>
<property name="wxOrderService"
ref="wxOrderService" >
</property> /就是他们引起了。
<property name="fileProcessManage">
<ref bean="fileProcessManage" />
</property>
</bean>
2,
public abstract class FftController extends BaseController {
protected WxOrderService wxOrderService;
public void save(HttpServletRequest request, HttpServletResponse response) {
logger.info("save info begin...");
Map<String, Object> result = new HashMap<String, Object>();
try {
String wxOpenId = request.getParameter("wxOpenId");
String applyId = request.getParameter("applyId");
String wxModuleType = request.getParameter("wxModuleType");
//UploadFile1(request,response,applyId);
if (StringUtil.isEmpty(wxOpenId) || StringUtil.isEmpty(applyId)
|| StringUtil.isEmpty(wxModuleType)) {
result.put("code", "001");
result.put("desc", "必填参数为空");
super.toJson(result, response);
return;
}
// 获取request里的所有参数,作为orderParam
String paramJson = packageOrderParam(request);
// 查询对象
WxOrder wxOrder = new WxOrder();
wxOrder.setWxOpenId("666");
wxOrder.setApplyId(applyId);
wxOrder.setWxModuleType("777");
// 查询是否已经存在 wxOrderService就是在这空了的
WxOrder query = wxOrderService.findWxOrderByModel(wxOrder);
if (null != query) {
wxOrder = query;
wxOrder.setOrderParam(paramJson);
wxOrder.setLastupDate(new Date());
wxOrderService.updateWxOrder(wxOrder);
} else {
wxOrder.setOrderParam(paramJson);
wxOrder.setCreateDate(new Date());
wxOrder.setLastupDate(new Date());
wxOrderService.createWxOrder(wxOrder);
}
result.put("code", "000");
result.put("desc", "success");
super.toJson(result, response);
return;
} catch (Exception e) {
logger.error("", e);
result.put("code", "099");
result.put("desc", "系统异常");
super.toJson(result, response);
return;
}
}
3.
public class WXFFanController1 extends FftController {
protected WxOrderService wxOrderService;/就是他们引起的。
public void setWxOrderService(WxOrderService wxOrderService) {
this.wxOrderService = wxOrderService;
}
产生,为空的原因主要是因为父类中已经注入了,而在子类中又注入了一遍,产生空了。解决方案就是把子类的删除掉,子类可以直接用wxOrderService。不需要重新注入的。
<bean id="wxFFanController1" class="com.bill99.query.controller.WXFFanController1" parent="fftController">
<property name="methodNameResolver">
<ref bean="paramResolver" />
</property>
<property name="fileProcessManage">
<ref bean="fileProcessManage" />
</property>
</bean>
public class WXFFanController1 extends FftController {
}
异常-----spring明明注入了Service到Action中,为什么运行的时候Service为空,在抽象类中,有子类来继承的的更多相关文章
- Spring(二十三):Spring自动注入的实现方式
注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解包含:Autowrired/Resource/Qualifier/Service/Controller/Repository/C ...
- Spring中抽象类中使用EmbeddedValueResolverAware和@PostConstruct获取配置文件中的参数值
我的需求: 我有一个 abstract class 中包含了很多子类中需要用到的公共方法和变量,我想在抽象类中 使用@Value获取*.properties中的值.但是@Value必须要在Spring ...
- spring的注入
1 可能遇到的问题: 异常信息 NoSuchBeanDefinitionException: No matching bean of type [...]或是NoSuchBeanDefinitionE ...
- Spring的注入问题
作下笔记,Spring的注入问题[多个实例问题] 解决方案如下: package student.life.support.platform.service.impl; import javax.an ...
- Spring依赖注入 --- 简单使用说明
Spring依赖注入 --- 简单使用说明 本文将对spring依赖注入的使用做简单的说明,enjoy your time! 1.使用Spring提供的依赖注入 对spring依赖注入的实现方法感兴趣 ...
- 为什么多线程、junit 中无法使用spring 依赖注入?
为什么多线程.junit 中无法使用spring 依赖注入? 这个问题,其实体现了,我们对spring已依赖太深,以至于不想自己写实例了. 那么到底是为什么在多线程和junit单元测试中不能使用依赖注 ...
- spring整合mybatis错误:Could not autowire field: com.kjczwl.ssm.service.ItemsService com.kjczwl.ssm.controller.ItemsController.itemsservice;
运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:Could not autowire field: com.kj ...
- Spring ——依赖注入配置一些知识点
依赖注入 依赖注入的原理与实现 依赖注入(DI)和依赖查找(Dependency Lookup)共同组成 控制反转(IoC).从原理的角度来说,依赖注入和控制反转是没 有不同的,可以看作是从两个角度来 ...
- Spring IOC 注入方式详解 附代码
引言 Spring框架作为优秀的开源框架之一,深受各大Java开发者的追捧,相信对于大家来说并不陌生,Spring之所以这么流行,少不了他的两大核心技术IOC和IOP.我们这里重点讲述Spring框架 ...
随机推荐
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- POJ1741Tree [点分治]【学习笔记】
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20098 Accepted: 6608 Description ...
- C#之文件缓存
写在开头 今天就放假了,照理说应该写今年的总结了,但是回头一看,很久没有写过技术类的文字了,还是先不吐槽了. 关于文件缓存 写了很多的代码,常常在写EXE(定时任务)或者写小站点(数据的使用和客户端调 ...
- POI导出多张图片到Excel
package com.sun.office.excel; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStr ...
- IDEA的优质使用博客资源
intelliJ idea 使用技巧&方法 IntelliJ IDEA 常用设置讲解 IntelliJ IDEA 详细图解最常用的配置 ,适合刚刚用的新人. IntelliJ IDEA 常见文 ...
- 异步任务利器Celery(一)介绍
django项目开发中遇到过一些问题,发送请求后服务器要进行一系列耗时非常长的操作,用户要等待很久的时间.可不可以立刻对用户返回响应,然后在后台运行那些操作呢? crontab定时任务很难达到这样的要 ...
- python学习:简单的wc命令实现
#!/usr/bin/python import sys import os try: fn = sys.argv[1] except IndexError: print &q ...
- CodeFirst+MySQL+.Net Core配置详情
EF 基础操作:http://www.cnblogs.com/M-LittleBird/p/5852395.html 一.使用CodeFirst模式 1.在需要添加的项目上右键点击选择添加ADD.NE ...
- Sqlserver将数据从一张表插入到另一张表
1.如果是整个表复制表达如下: insert into table1 select * from table2 2.如果是有选择性的复制数据表达如下: insert into table1(colum ...
- SpringBoot Hello World
本文首发于我的github博客 前言 SpringBoot是Spring MVC升级版,基于『约定优于配置』的原则,快速开发出web程序. 环境 本系列笔记环境如下: Sun JDK1.8.0_20 ...