问题

Description:

A component required a bean of type 'com.course.server.mapper.TestMapper' that could not be found.


Action:

Consider defining a bean of type 'com.course.server.mapper.TestMapper' in your configuration.

解决

我用了mybatis,在mapper层忘记加@Mapper注解了,加上后就可以了

其他情况:

  1. service层要加上@Service
  2. 如果注解都加了,还和扫描包配置的目录层级有关系,注意检查一下

使用@mapper后,不需要在spring配置中设置扫描地址,通过mapper.xml里面的namespace属性对应相关的mapper类,spring将动态的生成Bean后注入到ServiceImpl中

参考链接:@Mapper的作用

更多推荐

Consider defining a bean of type ‘com.course.server.mapper.TestMapper‘ in your c