org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘tes

废话不多说,今天在用springboot做一个东西的时候用到了mybatis

炸了炸了,我们以前用spring-boot加载mybatis都没什么问题,可今天就出现了问题,下面是我报错的问题:

下面是两段程序的报错,我中途修改代码以为成功了,没想到一运行就又报错=

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testController': 
Unsatisfied dependency expressed through field 'service'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serviceImpl': 
Unsatisfied dependency expressed through field 'usermapper'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usermapper' 
defined in file [D:\TestMaven\springboot4\target\classes\com\xiaoran\springboot4\demo\mapper\Usermapper.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 java.io.FileNotFoundException: Could not open ServletContext resource [/mybatis-config.xml]
2021-11-15 21:39:21.249 ERROR 13816 --- [nio-8080-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.xiaoran.springboot4.demo.mapper.Usermapper.getUser] with root cause

大家先看看网上的怎么说的把我简单给说一下:

(1)就是你们的mybatis-mapper.xml中的 amespace和你们标签的id对不上,
(2)还有一种就是你们的service注解,忘记标在你们的接口实现类上面
(3)接下来这个是我自己总结的,全网独一份:我们在用spring-boot引入mybatis的时候,按照以前在spring中学习的时候我们都要求去写:两个xml一个是Mybatis-config.xml和mybatis-mapper.xml,我也是这样写的哈哈哈哈,但是我们后面在application.yml中写的时候我也把两个都注入进去了。

application.yml中写的是

 mybatis:
    mapper-locations: mybatis/mapper/Usermapper.xml
    config-location: mybatis/mybatis-config.xml

如果你也是这样写的话,那么恭喜你写错了,我们的mybatis-config.xml在这里本身就是空文件夹,如果你配置进去的化,springboot会按照你写入的mybatis-config.xml去找mapper,那么肯定是找不到的,所以这里我们就只能写一个mybatis-mapper.xml进去。

 mybatis:
    mapper-locations: mybatis/mapper/Usermapper.xml
  

还有在说一点,在这里我们可千万不要去画蛇添足去写 在别人中间写个classpath*: 千万不能加,加了就会报错。。。。。。。。。。。。。懂了吧。有问题可以评论区留言,我看到就会回复的。。。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

O_0..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值