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 & ...
随机推荐
- 解决ScrollView中的ListView无法显示全
问题描述: ListView加入到ScrollView中之后,发现只能显示其中一条,具体原因得看一下源代码.现在先贴一下方案 (转自:http://blog.csdn.net/hitlion2008/ ...
- hadoop深入研究:(七)——压缩
转载请标明出处:hadoop深入研究:(七)——压缩 文件压缩主要有两个好处,一是减少了存储文件所占空间,另一个就是为数据传输提速.在hadoop大数据的背景下,这两点尤为重要,那么我现在就先来了解下 ...
- POJ 2365 Rope(水题)
[题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们能够看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度事实上就 ...
- android中file的使用实例
File是android的4种存储方式的一种.File就是文件的意思一个文件,你无非是想进行读写操作.所以这就用到两个流.一个数输入流,一个是输出流.FileOutstream,和FileInputS ...
- Hermes和开源Solr、ElasticSearch
不同
Hermes和开源Solr.ElasticSearch不同 谈到Hermes的索引技术.相信非常多同学都会想到Solr.ElasticSearch.Solr.ElasticSearc ...
- SQL Server Compact免安装部署
原文:SQL Server Compact免安装部署 情况 应用程序中的EF使用了SQL Server Compact,打包部署到客户机器上后提示数据库连接异常,信息类似”配置节“.”Provider ...
- Java使用反射机制优化工厂方法
我先举个例子,有一个接口People,这个接口有一个方法: package com.wjy.reflect; public interface People { public abstract voi ...
- 解决eclipse project前出现红色感叹号 但没有提示错误出在什么地方build path jar包也没报错
在problems窗体能够看到错误信息 菜单条 window-->show view-->problems 或alt+shift+q 然后按x 又一次选一下包就攻克了
- 一起来开发Android的天气软件(四)——使用Gson解析数据
离上一篇文章过去才4.5天,我们赶紧趁热打铁继续完毕该系列的天气软件的开发. 承接上一章的内容使用Volley实现网络的通信.返回给我们的是这一串Json数据{"weatherinfo&qu ...
- hadoop ,传智播客目录
一.Hadoop入门,了解什么是Hadoop 1.Hadoop产生背景 2.Hadoop在大数据.云计算中的位置和关系 3.国内外Hadoop应用案例介绍 4.国内Hadoop的就业情况分析及课程大纲 ...