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 ...
随机推荐
- IntelliJ IDEA 2019 的安装与破解
IDEA 全称 IntelliJ IDEA,是java编程语言开发的集成环境.IntelliJ在业界被公认为最好的java开发工具,尤其在智能代码助手.代码自动提示.重构.J2EE支持.各类版本工具( ...
- luogu_P3373 solution
luogu_P3373 solution Problme Description Now, you have a known series, there are three operations: ...
- e3mall商城的归纳总结1之项目的架构
首先来谈谈e3mall商城,e3mall商城是黑马推出一个学习的项目,前身是淘淘商城.两个用的技术差不多.,但由于后期加了一些新技术,更名为e3mall商城.本商城为分布式商城,主要用到的技术使mav ...
- MES系统与喷涂设备软件基于文本文件的数据对接方案
产品在生产过程中除了记录产品本身的一些数据信息,往往还需要记录下生产设备的一些参数和状态,这也是MES系统的一个重要功能.客户的药物支架产品,需要用到微量药物喷涂设备,客户需要MES系统能完整记录下每 ...
- Pytest allure自定义特性场景功能
@allure.feature @allure.story allure支持用户对测试用例进行功能模块的自定义,并展示在报告中 需要在测试用例代码中加上装饰器@allure.feature[加在测试类 ...
- 【Pytorch-入门】windows下的环境搭建(经验证成功~)
前言 实验需要,之前使的tensorflow[因为自己手边的服务器都是windows环境TT...],但身边的师兄们用的都是pytorch,自己查了查现在做科研基本上都是用的pytorch,而且现在p ...
- vue-element-admin改造接入后台,搭建有来商城youlai-mall后台前端管理平台
一. 前言 本篇基于有来商城youlai-mall微服务项目,搭建后台前端管理平台,技术选型希望通过本篇文章你可以,技术解决方案选择了vue-element-admin.希望通过本篇文章你可以vue- ...
- 5 art-template
npm 在终端命令下执行装包,就会在该目录下产生一个node_modules包 art-template地址:https://aui.github.io/art-template/zh-cn/docs ...
- 查看Linux虚拟机是什么架构
uname -a 可以看出此虚拟机是x86架构,64位
- Agumaster添加股票日交易爬虫画面