springboot @Bean创建容器失败如何解决

一、大家先来看我的报错
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userServiceImpl’: Unsatisfied dependency expressed through field ‘userMapper’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userMapper’ defined in file [F:\springboot\target\classes\com\lty\springboot\mapper\UserMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required
额。。。。。。 或许有点乱但是应该没啥关系,这段报错的意思就是告诉咱们,创建bean 容器userController 创建失败。一开始遇到这个我也是头皮发麻,心里一万个尼玛,太悲催了。不过,最终还是通过小铁的不懈努力终于解决了;
在这里插入图片描述

二、下面我先讲讲如何解决
1)检查pom.xml文件是否缺少依赖

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.10</version>
</dependency>

2)检查你的application 没有在这个文件配置来映射的话,会找不到你的mapper文件

mybatis:
  mapper-locations:  classpath:mapper/ *.xml
  type-aliases-package: com.lty.springboot.mapper

3)检查你的impl层是否添加了@service注解
在这里插入图片描述

4)检查你的启动类是否添加了@MapperScan注解
注意:里面的地址直接指到你的mapper
在这里插入图片描述
5)还有要检查你的启动类,一定要放在springboot(你的包)下面 别放错了,否则启动会找不到的
在这里插入图片描述
我的错误就是因为缺少了pom.xml 依赖一直找不到注解,不过还好找到了,真的好惨。
大家以后写代码要注意心细一些我感觉就不会报这种错误了,小铁也是为了自己的不细心买了1个小时的单。
如果经过以上的步骤还是报错,大家可以在底下留言。小铁看见的话 就会给大家解答,以上皆为自己总结,如果有误请见谅。

如果小铁的文章对大家有帮助的话,就请点个赞吧!!!

我是小铁,一个实力与逗比的结合体。 ——小铁

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值