关于SpringBoot结合mybatis后遇到的坑
先放出我遇到的出错信息,真的出错了可以先看看出错信息,就能更加高效准确的搜索到信息
我的报错日志:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'adminServiceimpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminServiceImpl': Unsatisfied dependency expressed through field 'myMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myMapper' defined in file [D:\Program Data\Java_workbench\idea\demo\target\classes\com\example\demo\Mapper\MyMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\Program Data\Java_workbench\idea\demo\target\classes\mapper\AdminMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\Program Data\Java_workbench\idea\demo\target\classes\mapper\AdminMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.example.demo.Mapper.AdminMapper.BaseResultMap
关键在于红色这一行,这个说我的映射关系已经存在,这一个就说明我极有可能是重复声明了映射关系,也就是mapper,检查发现我在application.properties文件和自己配置的mybatis配置文件中都有说明mapper的位置,这样会导致对mapper的重复扫描,因此注释掉其中一个即可,我直接注释掉application.properties里的
mybatis.mapper-locations=classpath:mapper/*.xml
注释掉这一行即可
(记得报错信息着重看最后的报错信息,因为异常捕获是从上而下的,最后的才是最底层的报错,也更准确)
关于SpringBoot结合mybatis后遇到的坑的更多相关文章
- springboot整合mybatis遇到的那些坑
1.接口类(指*Mapper.java)在spring中注册的问题 当控制台打印如下信息: A component required a bean named '*Mapper' that could ...
- springboot+dubbo+mybatis多模块项目invalid boundexception
invalid boundexception的原因大抵是因为mybatis扫描不到mapper映射文件(xml),无法将mapper接口类(java)中的接口与mapper映射器绑定起来.这可能是因为 ...
- springboot引入mybatis遇到的坑
前边分享了springboot项目的创建及springboot项目的默认配置文件等,想温习的小伙伴可移步至文章末尾阅读,感谢.今天来分享下springboot引入mybatis框架的步骤,有小伙伴 ...
- SpringBoot14 SpringBoot整合mybatis
1 版本说明 springboot:2.0 jdk:1.8 2 创建springBoot项目 创建项目时勾选必要web,MySQL,mybatis相关依赖 创建完成后再pom文件中添加自动部署.lom ...
- 记一次SpringBoot 开发中所遇到的坑和解决方法
记一次SpringBoot 开发中所遇到的坑和解决方法 mybatis返回Integer为0,自动转型出现空指针异常 当我们使用Integer去接受数据库中表的数据,如果返回的数据中为0,那么Inte ...
- springboot中mybatis逆向工程与分页的应用
最近在项目中应用到springboot与mybatis,在进行整合过程中遇到一些坑,在此将其整理出来,便于以后查阅与复习. 项目运行环境为:eclispe+jdk1.8+maven 一.搭建Sprin ...
- SpringBoot整合mybatis、shiro、redis实现基于数据库的细粒度动态权限管理系统实例
1.前言 本文主要介绍使用SpringBoot与shiro实现基于数据库的细粒度动态权限管理系统实例. 使用技术:SpringBoot.mybatis.shiro.thymeleaf.pagehelp ...
- Springboot与Mybatis整合
最近自己用springboot和mybatis做了整合,记录一下: 1.先导入用到的jar包 <dependency> <groupId>org.springframework ...
- springboot+springmvc+mybatis项目整合
介绍: 上篇给大家介绍了ssm多模块项目的搭建,在搭建过程中spring整合springmvc和mybatis时会有很多的东西需要我们进行配置,这样不仅浪费了时间,也比较容易出错,由于这样问题的产生, ...
随机推荐
- Java基础自学小项目
实现一个基于文本界面的<家庭记账软件> 需求:能够记录家庭的收入,支出,并能够收支明细表 主要涉及一下知识点: - 局部变量和基本数据类型 - 循环语句 - 分支语句 - 方法调用和返回值 ...
- vue封装一个弹框组件
这是一个提示框和对话框,例: 这是一个组件 eject.vue <template> <div class='kz-cont' v-show='showstate'> &l ...
- 第01章-Java SE8的流库
从迭代到流的操作 流表面上看起来和集合很类似,都可以让我们转换和获取数据,但是它们之间存在着显著的差异 流并不存储其元素,这些元素可能存储在底层的集合中,或者是按需生成的 流的操作不会修改其数据源 流 ...
- 我的2019年总结和一些2020年的flag
我的2019年总结和一些2020年的flag 前言 2019年在我的人生中注定是里程碑的一年,主要是我毕业了.本篇总结主要聊一些2019年经历的事以及对于自己2020年的期待 1. 再见2019 1. ...
- 003-try-catch-finally-return执行顺序问题
一.try-catch-finally-return执行顺序问题 0.原始执行顺序 try - > finally try -> catch -> finally 1.try cat ...
- 2019 南京网络赛 B super_log 【递归欧拉降幂】
一.题目 super_log 二.分析 公式很好推出来,就是$$a^{a^{a^{a^{...}}}}$$一共是$b$个$a$. 对于上式,由于指数太大,需要降幂,这里需要用到扩展欧拉定理: 用这个定 ...
- dfs求连通块
递归 递归是什么?绝大部分人都会说:自己调用自己,刚开始我也是这样理解递归的.确实没错,递归的确是自己调用自己.递归简单的应用:编写一个能计算斐波那契数列的函数,也就是这样: int fb(int n ...
- Go语言GC实现原理及源码分析
转载请声明出处哦~,本篇文章发布于luozhiyun的博客:https://www.luozhiyun.com/archives/475 本文使用的 Go 的源码1.15.7 介绍 三色标记法 三色标 ...
- 20184307 实验三 Socket编程技术
实验三 Socket编程技术 学号 20184307 2019-2020-2 <Python程序设计>实验三报告 课程:<Python程序设计> 班级:1843 姓名:章森洋 ...
- 敏捷史话(十三):我被 Facebook 解雇了——Kent Beck
2011年,Kent Beck 加入了 Facebook .那时候的他已年过半百,几十年的经验让他自认为非常了解软件行业.在 Facebook 的新手训练营期间,Kent 开始意识到,Facebook ...