springmvc与mybatis整合时 java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 异常
今天在整合springmvc与mybatis时,启动服务器遇到这样一个问题,
by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required at org.springframework.util.Assert.notNull(Assert.java:112)
异常的意思是 缺少sqlSessionFactory 或者是 sqlSessionTemplate
我的dao层是利用继承SqlSessionDaoSupport 然后可以直接通过this.getSqlSession() 来进行数据库的操作。
后来通过搜索以及查看源代码发现,mybatis-spring 1.2版本没有自动注入sqlSessionFactory
解决方法是手动注入
1 public class BaseDaoImpl extends SqlSessionDaoSupport {
2
3 @Autowired
4 public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
5 super.setSqlSessionFactory(sqlSessionFactory);
6 }
7 }
然后在将dao实现类继承BaseDaoImpl就可以使用了
1 @Repository
2 public class PersonDaoImpl extends BaseDaoImpl implements PersonDao {
3
4 String ns = "cn.tx.mapper.PersonMapper.";
5 @Override
6 public void savePerson(Person p) {
7 this.getSqlSession().insert(ns+"savePerson", p);
8 }
9
10 @Override
11 public Person selectPersonById(Integer personId) {
12 return this.getSqlSession().selectOne(ns+"selectPersonById", personId);
13 }
14
15 @Override
16 public void update(Person p) {
17 this.getSqlSession().update(ns + "update", p);
18 }
19
20 @Override
21 public void delete(Integer personId) {
22 this.getSqlSession().delete(ns + "delete", personId);
23 }
24
25 @Override
26 public List<Person> selectPersonByCondition(QueryCondition qc) {
27 return this.getSqlSession().selectList(ns + "selectPersonByCondition", qc);
28 }
29
30 }
springmvc与mybatis整合时 java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 异常的更多相关文章
- springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...
- MyBatis与Spring MVC结合时,使用DAO注入出现:Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
错误源自使用了这个例子:http://www.yihaomen.com/article/java/336.htm,如果运行时会出现如下错误: Invocation of init method fai ...
- Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required [ IDEA mybatis项目报错 ]
今天笔者用Springboot框架整合Mybatis做一个小小的项目: 代码写完,在运行项目时,IDEA给我报了3处错误: org.springframework.beans.factory.Unsa ...
- 使用 Jenkins 打包成功后 运行 出现 Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
linux 运行时 错误日志 Error starting ApplicationContext. To display the conditions report re-run your appli ...
- springboot下Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
已检查jar包是否引入 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId ...
- Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...
- spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 无法启动 ...
- springmvc错误 Spring3.X jdk8 java.lang.IllegalArgumentException
最近在学习springmvc--碰到一个特别蛋疼的错误 javax.servlet.ServletException: Servlet.init() for servlet springMVC thr ...
- 图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range解决方案
版权声明:本文为博主原创文章,未经博主允许不得转载. 06-03 20:45:24.143: E/AndroidRuntime(1230): FATAL EXCEPTION: main06-03 20 ...
随机推荐
- [CSP-S2019]树的重心 题解
CSP-S2 2019 D2T3 考场上扔了T2来打这题的部分分,然后没看到数据范围是等号,不知道怎么判完全二叉树然后40分滚粗…… ---- 思路分析 很容易想到$O(n^2)$每次暴力找重心,这个 ...
- 网站会不会因为同IP网站被K而受到惩罚
http://www.wocaoseo.com/thread-289-1-1.html 使用虚拟主机的网站会不会因为同一个IP或同一台服务器上有其他网站作弊被处罚而受连累,也被惩罚? 复制代码 百度官 ...
- 测试必须学spring RESTful Service(上)
文末我会说说为什么测试必须学spring. REST REST,是指REpresentational State Transfer,有个精辟的解释什么是RESTful, 看url就知道要什么 看met ...
- 招新裁老,两面派互联网大厂,培训三个月,就拿15K,凭什么?
看到一位朋友在发帖子求问:亲身经历,(如有谎言我名字倒过来写)一个大学同学18年毕业的.在兰州一个二本学的兽医农牧,毕业难找工作,去深圳一个机构培训了三个月吧,然后就去做大数据 算法了,然后又去做ja ...
- day42:HTML标签和CSS选择器
目录 1.HTML 1.1 文档结构 1.2 head标签 1.3 body标签 1.3.1 h1-h6标签 1.3.2.br标签:换行 1.3.3.hr标签:一行横线 1.3.4 a标签:超链接标签 ...
- CRMEB单商户商城系统v4.0源码,含前端uni-app源码
CRMEB商城系统是基于ThinkPhp6.0+Vue开发的一套新零售移动电商系统,CRMEB系统就是集客户关系管理+营销电商系统,能够快速积累客户.会员数据分析.智能转化客户. 有效提高销售.会员维 ...
- 删除MBR分区如何使用光盘恢复
1.备份MBR分区表 dd if=/dev/sda of=/data/mbr.bak bs=1 count=64 skip=446 分区表前512字节分为三部分,第一部分446字节与启动相关 ...
- Copy a Xaml object
<Control.Resources> <Button Click="Button_OnClick" x:Key="MyButton"> ...
- Vue企业级优雅实战03-准备工作04-全局设置
本文包括如下几个部分: 初始化环境变量文件 JS 配置文件初始化:如是否开启 Mock 数据.加载本地菜单.URL 请求路径等: 国际化文件初始化:初始化国际化文件的结构: 整合 Element UI ...
- 万字长文,以代码的思想去详细讲解yolov3算法的实现原理和训练过程,Visdrone数据集实战训练
以代码的思想去详细讲解yolov3算法的实现原理和训练过程,并教使用visdrone2019数据集和自己制作数据集两种方式去训练自己的pytorch搭建的yolov3模型,吐血整理万字长文,纯属干货 ...