日期:2014-05-18  浏览次数:20762 次

spring配合Mybatis 调用有返回结果集的存储过程,总是报java.lang.nullpointerexception 错误

这是我的mapper的内容,resultMap中type的bean:Reason是按照返回结果集设置的。

<mapper namespace="cn.com.casking.statistics.dao.ReasonShowMybatisDao">
<resultMap type="cn.com.casking.statistics.domain.Reason" id="reasonMap">
<result property="id" column="ID"/>
<result property="organName" column="ORGAN_NAME"/>
<result property="praxisTitle" column="PRAXIS_TITLE"/>
<result property="subJectiveDesc" column="SUBJECTIVE_DESC"/>
</resultMap>

<select id="callResult" parameterType="java.util.HashMap" statementType="CALLABLE">
<![CDATA[
{call sp_query_que_sub_result(#{sqlparm,mode=IN,jdbcType=VARCHAR},#{outresult,mode=OUT,jdbcType=CURSOR,javaType=java.sql.ResultSet,resultMap=reasonMap})}
]]>
</select>
</mapper> 


下面是我的interface

@MyBatisRepository
public interface ReasonShowMybatisDao {

void callResult(Map<String, Object> map);
}


服务层代码

@Component
@Transactional(readOnly = true)
public class ReasonShowService {

@Autowired
private ReasonShowMybatisDao reasonShowMybatisDao;

public void callResult(Map<String, Object> map){

reasonShowMybatisDao.callResult(map);
}


控制层调用:

Map<String,Object> map= new HashMap<String,Object>();
map.put("sqlparm",sqlparm);
map.put("outresult",OracleTypes.CURSOR);
reasonShowService.callResult(map);//这句调用出错,报java.lang.nullpointerexception 


找了很久,没有找到原因,
最后只能用最原始的jdbc调用,希望大神给与指导
40分会不会太少?
Mybatis?调用存储过程 nullpointerexception

------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

控制层调用,有没有注入?相关注入代码贴上来看看


有注入的

@Autowired
public ReasonShowService reasonShowService;

1. reasonShowService所在的类有没有加上@Service之类的注解?
2. reasonShowService所在的类,扫描配置的包路径包含它没?


1.reasonShowService不需要@Service这样的注解的了,一直都是这么用的,没有问题。我用的是spring MVC
2.已经全部有@Autowired的注解了,不需要再扫描service和dao文件,只需要扫描control文件即可

疑问:使用@Autowired必须要有@Service吗?

答案:a、可以有;b、可以没有

a可以有:Spring文件中没有配置bean时两个必须有,否则确实@Service的话Spring无法找到对应的bean就会报异常。

b可以没有:在Spring文件中配置bean这对应的接口实现类不需要@Service,bean配置如下:

<bean id="crmOrderDao" class="com.companyName.projectName.dao.impl.CrmOrderDaoImpl"  parent="BaseSqlMapClientDAO">

</bean>

这个要不你加上@Service试试呗?
------解决方案--