之前一直用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. 如何为linux释放内存和缓存

    如何为linux释放内存和缓存_华陌飞尘_新浪博客 如何为linux释放内存和缓存    (2011-10-20 10:49:01)        标签:    linux    swap    me ...

  2. Android 编译时出现r cannot be resolved to a variable

    问题:编译出现r cannot be resolved to a variable 原因:SDK的Tools没有安装 解决:在Android SDK Manager中安装Tools部分,包括如下4项, ...

  3. MySQL的Master/Slave群集安装和配置

    本文介绍MySQL的Master/Slave群集安装和配置,版本号安装最新的稳定版GA 5.6.19. 为了支持有限HA.我们用Master/Slave读写简单孤立的集群.有限HA这是当Master不 ...

  4. STM32 + RT Thread OS 学习笔记[四]

    1.  补注 a)      硬件,打通通讯通道 若学习者购买了学习板,通常可以在学习板提供的示例代码中找到LCD的相关驱动代码,基本上,这里的驱动的所有代码都可以从里面找到. 从上面的示意图可见,M ...

  5. Spring MVC的异步模式

    高性能的关键:Spring MVC的异步模式   我承认有些标题党了,不过话说这样其实也没错,关于“异步”处理的文章已经不少,代码例子也能找到很多,但我还是打算发表这篇我写了好长一段时间,却一直没发表 ...

  6. OCP读书笔记(4) - 配置备份设置

    4.Configuring Backup Settings 查看RMAN持久化设置 [oracle@easthome ~]$ rman target / RMAN> show all; SQL& ...

  7. OCA读书笔记(14) - 备份和恢复基本概念

    备份恢复概念 如何判断数据库的一致性 在mount状态下,oracle如何判断数据库的一致性 scn:system change number,它是数据库时钟 如何查询当前系统的scn: select ...

  8. HDU 4616 Game (搜索)、(树形dp)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4616 这道题目数据可能比较弱,搜索都可以AC,但是不敢写,哎…… 搜索AC代码: #include & ...

  9. GB2312引进和使用的字体

    一个:先上图看到的结果,下面的屏幕截图android在测试的结果"SD卡测试".."GPS测试"和其他字符24x24字体进来. 二:  1)简单介绍       ...

  10. Nagios监控系统的安装

    环境:centOS 6.5 X86 64位 nagios-4.08 步骤: 1.  最小化安装系统 2.  修改安全特性 关闭SELINUX     SELINUX=disabled 清除iptabl ...