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 ...
随机推荐
- swf反编辑软件带弹窗和跳转swf文件
http://www.wocaoseo.com/thread-296-1-1.html swf反编辑有啥用,在seo上.淘客上.网赚上,只有稍微牛逼些的人恐怕无人不知.无人不晓吧,这个软件是完全免费的 ...
- Pytest-allure 生成美观好看的测试报告
在我们使用pytest-allure生成测试报告时,需要分为以下几步来执行 1.pytest TestCal.py --alluredir=/tmp/my_allure_results[这一步,是设置 ...
- Unity - NGUI - 优化ScrollView的一些心的
ScrollView是NGUI非常好用的一个内置组件,但是效率不好,当子物体过多的时候,一旦开始拖动就帧数狂掉,我目前有3个解决思路: 1. NGUI自带的Example 8 - Scroll Vie ...
- 记录使用vs code两天的心得
一个字 就是骚~感觉以后写博客都省了
- WordCount(Java实现)
Github项目地址:https://github.com/linzworld/word-count 项目相关要求 题目描述 Word Count 实现一个简单而完整的软件工具(源程序特征统计程序). ...
- 5 art-template
npm 在终端命令下执行装包,就会在该目录下产生一个node_modules包 art-template地址:https://aui.github.io/art-template/zh-cn/docs ...
- upstream--负载
语法格式: upstream 负载名 { [ip_hash;] server ip:port [weight=数字] [down]; server ip:port [weight=数字]; } ...
- Visual Studio Code 下载安装
1.官网下载:https://code.visualstudio.com/ 2.下载完成后,点开如果是黑屏的话,右键勾上.
- 字符串split的用法
拆分字符串:张三:20|李四:40|王五:40 这个可以使用两次分割,第一次使用 | 分割,放到arr数组里,然后使用循环对arr[i]进行使用:分割 public static void main( ...
- Kubernetes-5:搭建企业级私有仓库Harbor
搭建企业级私有仓库Harbor 安装需求 python版本 >= 2.7 Docker引擎版本 >= 1.10 docker-compose版本 >= 1.6.0 安装环境 一.Py ...