当我们用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保存一致。