Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
之前一直用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 'sqlSessionFactory' or 'sqlSessionTemplate' are required的更多相关文章
- 关于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 ...
- 错误号码2003 Can't connect to MySQL server 'localhost' (0)
错误描写叙述 错误原因 近期,我一直都能够用SQLyog连接本地数据库,可是近几天却无法连接:而且一直都报上述错误,我查阅了非常多资料,发现有非常多中说法 总结一下 第一,MySQL中的my.ini出 ...
- 退役笔记一#MySQL = lambda sql : sql + ' Source Code 4 Explain Plan '
Mysql 查询运行过程 大致分为4个阶段吧: 语法分析(sql_parse.cc<词法分析, 语法分析, 语义检查 >) >>sql_resolver.cc # JOIN.p ...
- 【UVA】658 - It's not a Bug, it's a Feature!(隐式图 + 位运算)
这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...
- Error creating bean with name 'com.you.user.dao.StudentDaoTest': Injection of autowired dependencies
1.错误叙述性说明 七月 13, 2014 6:37:41 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadB ...
- error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
[root@luozhonghua ~]# /usr/bin/mysqladmin -u root password 'aaaaaa' /usr/bin/mysqladmin: connect t ...
- It's not a Bug, It'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 ...
- type 'simple Class' does not conform to protocol 'Example Protocol'错误
在看swift教程中"接口和扩展"这小部分. 在编写时提示"type 'simple Class' does not conform to protocol 'Examp ...
- uva_658_It's not a Bug, it's a Feature!(最短路)
It's not a Bug, it's a Feature! Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
随机推荐
- XCode所有版本
You can find the DMGs for Xcode and other development tools onhttps://developer.apple.com/downloads/ ...
- 动态分析maillog日志,把恶意链接直接用防火墙禁止
近期用 postfix + dovecot 搭建了一个邮件server, 被人当做垃圾邮件转发器,经过配置postfix 的黑白名单, postfix 提示成功的 REJECT 了垃圾邮件, 只是还是 ...
- BZOJ 1367([Baltic2004]sequence-左偏树+中位数贪心)
1367: [Baltic2004]sequence Time Limit: 20 Sec Memory Limit: 64 MB Submit: 521 Solved: 159 [ Subm ...
- hdu 4274 Spy's Work(水题)
Spy's Work Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 总结文件操作函数-文件夹(三)-C语言
获取.改变当前文件夹: 原型为: #include <unistd.h> //头文件 char *getcwd(char *buf, size_t size); //获取当前文件夹.相 ...
- cocos2d-x游戏循环和日程安排
每场比赛有一个程序执行周期继续.这是导演对象来管理非常维修.在运动假设需要的场景精神,我们可以使用计时器在游戏圈(Scheduler)精灵和其他对象进行调度. 由于Node类封装了Scheduler类 ...
- hdu 1251 统计难题 (map水过)
# include <stdio.h> # include <algorithm> # include <string> # include <map> ...
- Wix打包系列(一)如何使用wix制作安装程序
原文:Wix打包系列(一)如何使用wix制作安装程序 最近由于项目需要,需要给客户制作安装程序,一开始使用vs2005自带的打包工程来打包,但用了一段时间发现vs打包太死板,而且使用起来问题很多.收费 ...
- android圆角View实现及不同版本号这间的兼容
在做我们自己的APP的时候.为了让APP看起来更加的好看,我们就须要将我们的自己的View做成圆角的,毕竟主流也是将非常多东西做成圆角.和苹果的外观看起来差点儿相同,看起来也还不错. 要将一个View ...
- java与c/c++进行socket通信
比如Server端只接收一个结构Employee,定义如下: struct UserInfo { char UserName[20]; int UserId; }; struct Employ ...