之前一直用mybatis+mybatis-spring-1.1.1,系统升级mybatis使用后 mybatis-spring-1.2.2,

再其他配置均为改动的情况下执行出错: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

从SqlSessionDaoSupport 这个类的源代码中能够看出,原因是 mybatis-spring-1.2.0 中取消了自己主动注入
SqlSessionFactory 和
SqlSessionTemplate

/**
* Convenient super class for MyBatis SqlSession data access objects.
* It gives you access to the template which can then be used to execute SQL methods.
* <p>
* This class needs a SqlSessionTemplate or a SqlSessionFactory.
* If both are set the SqlSessionFactory will be ignored.
* <p>
* {code Autowired} was removed from setSqlSessionTemplate and setSqlSessionFactory
* in version 1.2.0.
*
* @see #setSqlSessionFactory
* @see #setSqlSessionTemplate
* @see SqlSessionTemplate
* @version $Id$
*/
public abstract class SqlSessionDaoSupport extends DaoSupport { private SqlSession sqlSession; private boolean externalSqlSession; public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
if (!this.externalSqlSession) {
this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
}
} public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSession = sqlSessionTemplate;
this.externalSqlSession = true;
}
……
}

1.1.1中代码片段为:

 1 public abstract class SqlSessionDaoSupport extends DaoSupport {
2
3 private SqlSession sqlSession;
4
5 private boolean externalSqlSession;
6
7 @Autowired(required = false)
8 public final void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
9 if (!this.externalSqlSession) {
10 this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
11 }
12 }
13
14 @Autowired(required = false)
15 public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
16 this.sqlSession = sqlSessionTemplate;
17 this.externalSqlSession = true;
18 }
19 ……
20
21 }

可能是为了解决多数据源的问题吧,取消了自己主动注入。

没用到多数据源,不太关心这个。

解决方式:由于我们dao层是继承于一个dao基类,所以仅仅要在这个基类中注入随意一个属性就可以。 SqlSessionFactory 在spring配置文件里已经配置。

1 public class BaseDaoImpl extends SqlSessionDaoSupport {
2 @Resource
3 public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
4 super.setSqlSessionFactory(sqlSessionFactory);
5 }

版权声明:本文博主原创文章,博客,未经同意不得转载。

Property &#39;sqlSessionFactory&#39; or &#39;sqlSessionTemplate&#39; are required的更多相关文章

  1. 关于Failed to convert property value of type [org.quartz.impl.StdScheduler] to required type [org.springframework.scheduling.quartz.SchedulerFactoryBean

    在一个业务类有下列属性 private SchedulerFactoryBeanscheduler; public SchedulerFactory BeangetScheduler() { retu ...

  2. 错误号码2003 Can&#39;t connect to MySQL server &#39;localhost&#39; (0)

    错误描写叙述 错误原因 近期,我一直都能够用SQLyog连接本地数据库,可是近几天却无法连接:而且一直都报上述错误,我查阅了非常多资料,发现有非常多中说法 总结一下 第一,MySQL中的my.ini出 ...

  3. 退役笔记一#MySQL = lambda sql : sql + &#39; Source Code 4 Explain Plan &#39;

    Mysql 查询运行过程 大致分为4个阶段吧: 语法分析(sql_parse.cc<词法分析, 语法分析, 语义检查 >) >>sql_resolver.cc # JOIN.p ...

  4. 【UVA】658 - It&#39;s not a Bug, it&#39;s a Feature!(隐式图 + 位运算)

    这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...

  5. Error creating bean with name &#39;com.you.user.dao.StudentDaoTest&#39;: Injection of autowired dependencies

    1.错误叙述性说明 七月 13, 2014 6:37:41 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadB ...

  6. error: &#39;Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2)&#39;

    [root@luozhonghua ~]#   /usr/bin/mysqladmin -u root password 'aaaaaa' /usr/bin/mysqladmin: connect t ...

  7. It&#39;s not a Bug, It&#39;s a Feature! (poj 1482 最短路SPFA+隐式图+位运算)

    Language: Default It's not a Bug, It's a Feature! Time Limit: 5000MS   Memory Limit: 30000K Total Su ...

  8. type &#39;simple Class&#39; does not conform to protocol &#39;Example Protocol&#39;错误

    在看swift教程中"接口和扩展"这小部分. 在编写时提示"type 'simple Class' does not conform to protocol 'Examp ...

  9. uva_658_It&#39;s not a Bug, it&#39;s a Feature!(最短路)

    It's not a Bug, it's a Feature! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

随机推荐

  1. BPL vs. DLL

    第一部分:有关包的介绍 一般我们编写编译一个DELPHI应用程序时,会产生一个EXE文件,也就是一个独立的WINDOWS应用程序.很重要的一点:区别于Visual Basic,DELPHI产生的是预先 ...

  2. ThinkPHP 自动创建数据、自动验证、自动完成详细例子介绍(十九)

    原文:ThinkPHP 自动创建数据.自动验证.自动完成详细例子介绍(十九) 1:自动创建数据 //$name=$_POST['name']; //$password=$_POST['password ...

  3. JavaScript 中的事件类型5(读书笔记思维导图)

    Web 浏览器中可能发生的事件有很多类型.如前所述,不同的事件类型具有不同的信息,而“ DOM3级事件”规定了以下几类事件. UI(User Interface,用户界面)事件:当用户与页面上的元素交 ...

  4. asp.net出现正在中止线程解决方案

    刚才又再次遇到了一个之前遇到的问题,在这里记录一下. 起因: 如果使用 Response.End.Response.Redirect 或 Server.Transfer 方法,将出现 ThreadAb ...

  5. poj3259(spfa判负环)

    题目连接:http://poj.org/problem?id=3259 题意:John的农场里N块地,M条路连接两块地,W个虫洞,虫洞是一条单向路,会在你离开之前把你传送到目的地,就是当你过去的时候时 ...

  6. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  7. 智能指针 shared_ptr 解析

    近期正在进行<Effective C++>的第二遍阅读,书里面多个条款涉及到了shared_ptr智能指针,介绍的太分散,学习起来麻烦.写篇blog整理一下. LinJM   @HQU s ...

  8. veridata实验举例(6)验证agent启动先后顺序是否对捕获update操作有影响

    veridata实验举例(6)验证agent启动先后顺序是否对捕获update操作有影响 续接veridata实验系列  上篇:"veridata实验举例(5)改动主键上的列值.update ...

  9. 微通道对接ERP、CRM、OA、HR、SCM、PLM和其他管理系统解决方案

    公司现有ERP.CRM.OA.HR.SCM.PLM等管理系统的对接微信公共平台服务 方法1:开放接口 企业开放现有系统数据接口给第三方,或由第三方开发数据接口对接微信公众平台 方法2:获取数据库 企业 ...

  10. iText操作word文档总结

    操作word文档的工具有很多,除了iText之外还有POI,但是POI擅长的功能是操作excel,虽然也可以操作word,但是能力有限,而且还有很多的bug,技术并不成熟,下面就重点介绍一种操作wor ...