解决 Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

在Spring3和Mybatis3整合的时候,dao层注入'sqlSessionFactory'或'sqlSessionTemplate'会报错解决办法如下

package com.alibaba.webx.MyWebxTest.myWebX.module.dao.impl;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 公用的DAO
 * @author zkn
 *
 */

public abstract class AbstractDao extends SqlSessionDaoSupport{

	/**
	 * Autowired 必须要有
	 */
	@Autowired
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
    	
        super.setSqlSessionFactory(sqlSessionFactory);
    }
	
}


原因是因为Mybatis3依赖的jar位 mybatis-spring-1.2.0.jar,这个版本及以上的版本中对SqlSessionDaoSupport类中的'sqlSessionFactory'或'sqlSessionTemplate'注入方式进行了调整。

猜你喜欢

转载自zknxx.iteye.com/blog/2301604
今日推荐