今天在整合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. cmd 和powershell 用git 显示乱码

    错误: 解决: 只需在环境变量中加入 LESSCHARSET=utf-8

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

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

  3. hadoop平台环境搭建

    centos01 配置静态ip vim /etc/sysconfig/network-scripts/ifcfg-eth0 见图1 修改主机名 vim /etc/sysconfig/network 见 ...

  4. linux 下分别使用pip2、pip3

    上次切换了Python2和Python3.但是Python3并没有pip,所有在Python3下不能安装包. 下面实现在Python3 下安装pip3 1,首先安装setuptools wget -- ...

  5. 2020年B2B外贸建站的终极教程

    本文目标:按照本建站教程的顺序操作,能够实现:基于全球份额最大的建站系统“wordpress”,从零搭建一个B2B外贸网站,且建站成本每年小于1000元(如果不计算自己投入的人力成本的话). 模板站点 ...

  6. 02 axios

    request.js import axios from 'axios' const config = require('@/config') const instance = axios.creat ...

  7. Jmeter 断言-检查点

    1. http请求/添加/断言/响应断言 2. 输入一个返回数据里没有的参数 3.果然报错了 断言的作用是用来查看接口文档里是否有自己想要的数据!

  8. 跟着兄弟连系统学习Linux-【day05】

    day05-20200602 p19.其他文件搜索命令 (百度搜索everything,安装,可以实现Windows秒级搜索文件)Linux中同样可以实现此功能. [locate 文件名]locate ...

  9. 把Employees显示在页面上

    项目代码下载:https://files.cnblogs.com/files/xiandedanteng/gatling20200429-1.zip 需求:从后台DB取出雇员数据,显示在前台页面上: ...

  10. Ant Jmeter Jenkins生成html测试报告

    Ant配置1. 将jmeter安装目录或者源码目录下\apache-jmeter-3.1\extras的ant-jmeter-1.1.1.jar复制到ant安装目录下apache-ant-1.10.3 ...