今天在整合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 异常的更多相关文章

  1. springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...

  2. 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 ...

  3. Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required [ IDEA mybatis项目报错 ]

    今天笔者用Springboot框架整合Mybatis做一个小小的项目: 代码写完,在运行项目时,IDEA给我报了3处错误: org.springframework.beans.factory.Unsa ...

  4. 使用 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 ...

  5. springboot下Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    已检查jar包是否引入 <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId ...

  6. Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...

  7. spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    spring boot 2.0.0 + mybatis 报:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 无法启动 ...

  8. springmvc错误 Spring3.X jdk8 java.lang.IllegalArgumentException

    最近在学习springmvc--碰到一个特别蛋疼的错误 javax.servlet.ServletException: Servlet.init() for servlet springMVC thr ...

  9. 图片缩放时java.lang.IllegalArgumentException: pointerIndex out of range解决方案

    版权声明:本文为博主原创文章,未经博主允许不得转载. 06-03 20:45:24.143: E/AndroidRuntime(1230): FATAL EXCEPTION: main06-03 20 ...

随机推荐

  1. 作为一个Java程序员连简单的分页功能都会写,你好意思嘛!

    今天想说的就是能够在我们操作数据库的时候更简单的更高效的实现,现成的CRUD接口直接调用,方便快捷,不用再写复杂的sql,带吗简单易懂,话不多说上方法 1.Utils.java工具类中的方法 1 /* ...

  2. 分享一个操作pdf文件的js文件-pdfObject.js(文件预览、下载、打印等操作都具备)

    获取相关资料或者源码的朋友可以关注下公众号,回复关键字pdf20200518即可

  3. 牛哄哄的celery

    一.什么是Celery 1.1.celery是什么 Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统,专注于实时处理的异步任务队列,同时也支持任务调度. Celery的架构由三部分组成, ...

  4. windows环境安装vue-cli及webpack并创建vueJs项目

    1. 安装node.js 2. 如果安装的是旧版本的 npm,可以通过 npm 命令来进行版本升级,命令如下: npm install npm -g npm网站服务器位于国外,所以经常下载缓慢或出现异 ...

  5. AD18 PCB中添加中文字符串显示乱码问题解决

    该问题是由于字符串的自体类型设置问题,AD默认是[stroke],我们点击[TrueType]即可正常显示.PS:AD18搞啥呢,默认显示输入内容不行吗,找半天!!!

  6. solrcloud集群版的搭建

    说在前面的话 之前我们了解到了solr的搭建,我们的solr是搭建在tomcat上面的,由于tomcat并不能过多的承受访问的压力,因此就带来了solrcloud的时代.也就是solr集群. 本次配置 ...

  7. React的几种组件

    一.函数组件 该函数在React中是一个有效的组件,可以接收唯一带有数据的props(代表属性)对象,并返回一个React元素.函数式组件要特别注意,组件名称首字母一定要大写.这种方式也成为无状态组件 ...

  8. SpringMVC实例及注解(二)

    @RequestMapping()除了修饰方法,还可以修饰类1.类定义处:提供初步的请求映射信息.相对于WEB应用的根目录2.方法处:提供进一步的细分映射信息.相对于类定义处的URL.若类定义处未标注 ...

  9. ASP.NET Core 进程内与进程外的性能对比

    ASP.NET Core 进程内与进程外的性能对比 本文内容是<深入去浅出ASP.NET Core>提供的扩展内容,毕竟在书里说进程内外的性能说明对比,对于初学者而言,稍微复杂了点. 我在 ...

  10. 存储过程中拼接SQL语句

    很多时候我们需要利用参数在存储过程中重新组织SQL语句,在存储过程中拼接的SQL语句只是一个字符串,不会被直接执行,所以加一个execute执行它就可以了.具体看如下演示代码: 代码: set ANS ...