A component required a bean of type ‘com.lw.mapper.StudentMapper‘ that could not be found.

在整合SpringBoot和MyBatis时遇到组件找不到StudentMapper的bean问题。解决方案包括:确保StudentMapper接口有@Mapper注解,检查mybatis-spring-boot-starter依赖是否已添加,并注意SpringBoot与mybatis-spring-boot-starter版本兼容性,避免版本冲突导致的问题。
摘要由CSDN通过智能技术生成

当我们用springboot整合mybatis时,发生以下错误

Description:

A component required a bean of type 'com.lw.mapper.StudentMapper' that could not be found.


Action:

Consider defining a bean of type 'com.lw.mapper.StudentMapper' in your configuration.

解决方法有:

1.查看你的mapper或者dao接口是否加了@mapper注解

@Mapper
public interface StudentMapper {
    Student getStudent(Integer id);
}

2.检查你的mybatis的依赖是否添加

<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

3.若以上都有添加,注意检查springboot和mybatis-spring-boot-starter的版本问题,我采用的springboot2.4.1与mybatis-spring-boot-starter3.0.0的版本冲突,因此显示这些问题,将mybatis-spring-boot-starter的版本与spring-boot保存一致。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

编程的小李

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

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

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

打赏作者

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

抵扣说明:

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

余额充值