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 failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
以下是解决思路,参考:http://blog.csdn.net/xkhgnc_6666/article/details/52063713说的解决方法,分析如下:
1、从字面上意思理解是注入时导致了混乱,相同类型的Bean不知道是注入SqlSessionFactory还是SqlSessionTemplate。
2、可以使用@Qualifier注解和@Autowired注解通过指定哪一个真正的Bean将会被装配来消除混乱,参考:http://wiki.jikexueyuan.com/project/spring/annotation-based-configuration/spring-qualifier-annotation.html,也就是具体指定使用上面的哪一个进行Bean注入。
具体解决代码,在DAO中加入如下代码:
@Autowired(required = false)
@Qualifier("sqlSessionFactory")
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
super.setSqlSessionFactory(sqlSessionFactory);
}
还可以这样写:
@Autowired(required = false)
public void setSqlSessionFactory(
@Qualifier("sqlSessionFactory")
SqlSessionFactory sqlSessionFactory) {
super.setSqlSessionFactory(sqlSessionFactory);
}
效果都是一样的。
MyBatis与Spring MVC结合时,使用DAO注入出现:Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required的更多相关文章
- Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required [ IDEA mybatis项目报错 ]
今天笔者用Springboot框架整合Mybatis做一个小小的项目: 代码写完,在运行项目时,IDEA给我报了3处错误: org.springframework.beans.factory.Unsa ...
- springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...
- springmvc与mybatis整合时 java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 异常
今天在整合springmvc与mybatis时,启动服务器遇到这样一个问题, by: java.lang.IllegalArgumentException: Property 'sqlSessionF ...
- MyBatis笔记----报错:Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/ij34/mybatis/applicationContext.xml]: Invocation of init method failed; nested exception is org.sp
四月 05, 2017 4:51:02 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRef ...
- IDEA报错: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.url' in value "${spring.datasource.url}"
运行审核流模块: 在ActivitiServiceApplication模块日志报错: Error starting ApplicationContext. To display the auto-c ...
- org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null
通过这个简单的案例,手把手教给你分析异常信息(适合初学者看) org.springframework.dao.InvalidDataAccessApiUsageException: The given ...
- spring Boot启动报错Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes
spring boot 启动报错如下 org.springframework.context.ApplicationContextException: Unable to start web serv ...
- jpa语句报 org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [2] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position
@Query("SELECT area from Area AS area WHERE area.state=0 AND area.name like %?1% ")Area fi ...
- spring报nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected错误
http://www.oschina.net/question/1539472_159699
随机推荐
- DHTML_____document对象的方法
<html> <head> <meta charset="utf-8"> <title>document对象的方法</titl ...
- Kali Linux的介绍
Kali Linux是什么? Kali Linux是一个渗透测试平台兼安全审计平台,它集成了多款漏洞检测.目标识别和漏洞利用工具. Kali Linux是专门用于渗透测试的Linux操作系统:基于De ...
- Spring.Net学习笔记(二)-数据访问器
Spring对ADO.NET也提供了支持,依赖与程序集Spring.Data.dll IDbProvider IDbProvider定义了数据访问提供器的基础,配置如下 <?xml versio ...
- Objective-C设计模式——外观Faced(接口适配)
外观模式 外观设计模式和适配器差不多,不过它门对对象控制的粒度不同,适配器一般只是控制一个系统和客户端的对接.外观则是用来抽象多个系统一起工作. 外观一般具有多个子系统,所以外观应持有多个子系统的引用 ...
- 常见Z纯CSS小样式合集(三角形)
三角形 .sanjiao{ width:0px; height: 0px; overflow: hidden; border-width: 100px; border-color: transpare ...
- MySQL 帮助类 MySQLHelper
/// <summary> /// MySqlHelper操作类 /// </summary> public sealed partial class MySQLHelper ...
- 生产环境4.3.5jboss内存调优
1.查看jboss的监控工具 http://XXX/jmx-console/htmladaptor 2.查看jvm的监控工具 jdk\bin jvisualvm.exe jmc.exe 3.查看jbo ...
- CAD梦想看图6.0安卓版详情介绍
下载安装 MxCAD6.0(看图版).2018.10.22更新,扫描下面二维码,安装CAD梦想看图: 下载地址: http://www.mxdraw.com/help_8_20097.html 软 ...
- JavaScipt30(第五个案例)(主要知识点:flex布局)
承接上文,这是第5个案例:这节没什么讲的,随便记录下吧,主要是用了flex布局与transform translateY,js部分和案例1类似. 附上项目链接: https://github.com/ ...
- BZOJ1509: [NOI2003]逃学的小孩 (树形DP)
题意:给一棵树 选三个点A,B,C 求A到B的再从B到C的距离最大值 需要满足AB的距离小于AC的距离 题解:首先树上的最大距离就想到了直径 但是被样例误导了TAT BC两点构成了直径 我一开始以为A ...