错误源自使用了这个例子: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的更多相关文章

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

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

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

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

  3. springmvc与mybatis整合时 java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required 异常

    今天在整合springmvc与mybatis时,启动服务器遇到这样一个问题, by: java.lang.IllegalArgumentException: Property 'sqlSessionF ...

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

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

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

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

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

  9. spring报nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected错误

    http://www.oschina.net/question/1539472_159699

随机推荐

  1. 基本的查询流【MSSQL】

    4个DML(Data Manipulation Language)命令 SELECT INSERT UPDATE DELETE 查询语法有一个特有的固定顺序 SELECT - FROM - WHERE ...

  2. WCF学习笔记(1)-一个完整的例子

    一.开发环境 IDE:VS2013 OS:Win10 IIS:IIS 10 二.开发流程 1.项目结构 2.添加一个WCF程序 3.删除系统自动生成的两个文件IService1.cs和Service1 ...

  3. jQuery学习笔记(1)-初探

    一.jQuery是什么 1.jQuery是一套JavaScript脚本库,而不是框架:就好比"System是程序集"是类库,而"ASP.NET MVC"是框架: ...

  4. (3)左右值再探与decltype

    Decltype 类型指示符 “引用从来都作为其所指对象的同义词出现,只有用在decltype处是一个例外” 理解: Decltype和auto区别: 1.     auto是从表达式类型推断出要定义 ...

  5. TypeError: slice indices must be integers or None or have an __index__ method

    由于除法/自动产生的类型是浮点型,因此出现上述错误,修正方法为,将/更改为// roi_gray_lwpCV = gray_lwpCV[y:y + h // 2, x:x + w] # 检出人脸区域后 ...

  6. Android基础TOP5_5:设置没有标题栏而且用系统壁纸当背景的界面

    在res/values目录下的style.xml设置如下 <style name="AppBaseTheme" parent="android:Theme.Wall ...

  7. ASP MVC

    V-view 显示层 C-controller 控制层 M-model 模型 D-database 数据库 S-Service 服务 D-Database/Dao 数据库/访问数据库的方法 View即 ...

  8. Stanford coursera Andrew Ng 机器学习课程第四周总结(附Exercise 3)

    Introduction Neural NetWork的由来 时,我们可以对它进行处理,分类.但是当特征数增长为时,分类器的效率就会很低了. Neural NetWork模型 该图是最简单的神经网络, ...

  9. 系统信号-signal.h

    #define SIGSEGV 11 /* segmentation violation */ #define SIGSYS 12 /* bad argument to system call */ ...

  10. JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)

    今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...