最近在学一个东西,要使用SSM新建一个案例,是这样滴,我有如下

  1. DeptDAO
  2. DeptService
  3. DeptServiceImpl
  4. DeptController
  5. Dept
  6. Mybatis

首先,我不是太清楚有了DAO还要有Service,不过这个不是本文章的重点。

重点是,报如下错,两个不同的错误吧

错误1:

2019-04-02 22:09:08.697 ERROR 12080 --- [nio-8001-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.vae.springcloud.dao.DeptDAO.findAll] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.vae.springcloud.dao.DeptDAO.findAll

错误2:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptController': Unsatisfied dependency expressed through field 'deptService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptServiceImpl': Unsatisfied dependency expressed through field 'deptDAO'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptDAO' defined in file [D:\Java Code\SpringCloud\provider\target\classes\com\vae\springcloud\dao\DeptDAO.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:\Java Code\SpringCloud\provider\target\classes\mybatis\mapper\DeptMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\Java Code\SpringCloud\provider\target\classes\mybatis\mapper\DeptMapper.xml]'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.vae.springcloud.dao.DeptDAO.findAll. please check mybatis/mapper/DeptMapper.xml and file [D:\Java Code\SpringCloud\provider\target\classes\mybatis\mapper\DeptMapper.xml]

很奇怪的错误,我看错误说没有bean,我在网上搜啊搜,网上的文章要么是抄袭的,要么是复制粘贴的,要么解释的答案简单的很,根本没有上升到我这个层次。我纠结了好几天,最终发现,错误居然是!!!居然是Mybatis的配置文件!!

我自己写的mybatis文章里面,说道,mybatis加载mapper.xml需要这样

<!-- 加载映射文件-->
<mappers>
<mapper resource="config/Message.xml"/>
</mappers>

这样是可行,但是,这就是造成我错误的原因。这种方式,我当时使用的是SqlSession来主动加载Mybatis文件的,现在我想自动的去映射,就不能这么写了,需要在yml配置文件里面写

mybatis:
config-location: classpath:mybatis/mybatis.cfg.xml # mybatis配置文件所在路径
type-aliases-package: com.atguigu.springcloud.entities # 所有Entity别名类所在包
mapper-locations: classpath:mybatis/mapper/**/*.xml # mapper映射文件

总之,这次的错误,完全是因为我不熟悉Mybatis造成的,为此困惑了好多天。

顺便一提,我正在学习的这个项目是SpringCloud,学会之后,我会专门去详细的讲SpringCloud。到时再提一提这个因为我的无知而造成的报错。

Error creating bean with name的更多相关文章

  1. 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;

    一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...

  2. [bigdata] 启动CM出现 “JDBC Driver class not found: com.mysql.jdbc.Driver” 以及“Error creating bean with name 'serverLogFetcherImpl'”问题的解决方法

    问题:“JDBC Driver class not found: com.mysql.jdbc.Driver”  通过以下命令启动cm [root@hadoop1 ~]# /etc/init.d/cl ...

  3. Spring 异常:Error creating bean with name

    异常信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxx' 我今 ...

  4. Java AOP nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice || Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0' 两个异常解决办法

    贴出applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...

  5. Error creating bean with name &#39;menuController&#39;: Injection of autowired dependency……

    出现了一大串错误 Error creating bean with name 'userController': Injection of autowired dependencies failed. ...

  6. Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; neste

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFacto ...

  7. eclipse 启动tomcat报Spring错误 Error creating bean with name 'serviceOrderBiz': Injection of autowired dependencies failed

    启动tomcat报异常,提示Sring无法创建serviceOrderBiz(第一行红字),继续看是因为有一个自动注入的字段无法注入ModuleInterfaceBiz(第二行红字),检查servic ...

  8. Error creating bean with name 'bookDao'

    “Error creating bean with name 'bookDao' defined in ServletContext resource [/WEB-INF/applicationCon ...

  9. Error creating bean with name &#39;memcachedClient&#39;...java.lang.OutOfMemoryError

    1,Tomcat启动报错例如以下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating ...

  10. Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'

    @Configuration public class HttpSessionConfig { @Bean public static ConfigureRedisAction configureRe ...

随机推荐

  1. SQLServer之删除视图

    删除视图注意事项 删除视图时,将从系统目录中删除视图的定义和有关视图的其他信息. 还将删除视图的所有权限. 使用 DROP TABLE 删除的表上的任何视图都必须使用 DROP VIEW 显式删除. ...

  2. Unity2018 Open C# Project Error

    错误日志 升级到Unity2018之后,使用 Open C# Project 打开VS工程,出现报错,无法启动VS. 错误日志如下: ArgumentException: Value does not ...

  3. redhat yum ISO 本地源

    先将ISO文件挂载起来: [root@racdb1 ~]# mount -o loop /opt/soft/rhel-server-6.8-x86_64-dvd.iso /mnt/iso [root@ ...

  4. LeetCode算法题-Diameter of Binary Tree(Java实现)

    这是悦乐书的第257次更新,第270篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第124题(顺位题号是543).给定二叉树,您需要计算树的直径长度. 二叉树的直径是树中 ...

  5. springclound

    https://blog.csdn.net/w893932747/article/details/80896315 //这个有怎么创建client的 https://blog.csdn.net/m0_ ...

  6. kernel笔记——内核编译与进程管理

    内核与操作系统 由于一些商业操作系统设计上的缺陷以及日益庞杂,“操作系统”的概念对很多人而言变得含糊不清.在进一步讨论Linux内核的话题前,我们先区分“内核”与“操作系统”这两个概念. 操作系统:指 ...

  7. c# 日期函数DateTime.ToString()日期的各种格式

    //c# datetime 格式化 DateTime dt = DateTime.Now; //2017/11/14 10:46:56 label1.Text = dt.ToString();//20 ...

  8. Java 8 新特性7-方法引用、继承

    (原) 方法引用: 方法引用有4种: 1.静态方法引用:类名::静态方法名 在java中,对集合的排序,我们常用java提供的 Collections.sort(List<T> list, ...

  9. Mac下使用国内镜像安装Homebrew

    First MBP上的brew很老了,就想把brew更新一下,顺便安装一下NodeJs.无奈更新的过程一直卡在网络下载,毫不动弹.想想,应该是Repo访问不到的原因,于是重装brew. 根据官网上的方 ...

  10. iOS开发基础-图片切换(2)之懒加载

    延续:iOS开发基础-图片切换(1),对(1)里面的代码进行改善. 在 ViewController 类中添加新的数组属性:  @property (nonatomic, strong) NSArra ...