异常-----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框架 ...
随机推荐
- BZOJ 3514: Codechef MARCH14 GERALD07加强版 [LCT 主席树 kruskal]
3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1312 Solved: 501 ...
- SqlServer varchar数据中类似于1.1.1.1这种值的排序方法
select * from 表名order by Convert(int,left(列名,charindex('.',列名+'.')-1)) asc, 列名asc charindex('.',列名) ...
- FileBeat安装配置
在ELK中因为logstash是在jvm上跑的,资源消耗比较大,对机器的要求比较高.而Filebeat是一个轻量级的logstash-forwarder,在服务器上安装后,Filebeat可以监控日志 ...
- 在ConcurrentModificationException异常上的联想
1.什么是ConcurrentModificationException? 大家都听说过快速报错fast-fail吧,fast-fail的发生就是说明发生了ConcurrentModification ...
- MathJax使用指南
MathJax使用指南 SublimePrettyJson Github CSDN-Markdown语法集锦 LaTex 简明教程 在Markdown中输入数学公式(MathJax) MathJax ...
- tensorflow_mnist数据集一直加载错误的解决办法
tensorflow数据集一直加载错误的解决办法: from tensorflow.examples.tutorials.mnist import input_data mnist = input_d ...
- kaggle-titanic 数据分析过程
1. 引入所有需要的包 # -*- coding:utf-8 -*- # 忽略警告 import warnings warnings.filterwarnings('ignore') # 引入数据处理 ...
- #pragma预处理命令
#pragma comment(lib,"XXX.lib") 表示链接XXX.lib这个库,和在工程设置里写上XXX.lib的效果一样. #pragma comment(linke ...
- 【Learning】最小点覆盖(二分图匹配) 与Konig定理证明
(附一道例题) Time Limit: 1000 ms Memory Limit: 128 MB Description 最小点覆盖是指在二分图中,用最小的点集覆盖所有的边.当然,一个二分图的最小 ...
- linux 云计算Openstack搭建
Openstack 由NASA和Reckspace合作研发并发起的项目,以Apache许可证为授权 云计算三大支柱模型 IaaS:基础架构即服务 提供服务器/虚拟主机/网络等设备资源 PaaS:平台即 ...