[Bug0010]Could not autowire. No beans of 'xxxxMapper' type found.

1、问题

Could not autowire. No beans of 'xxxxMapper' type found.

2、场景

在 Service 层中使用 @Autowired 注解注入Mapper 时候报错 Could not autowire. No beans of 'xxxxMapper' type found.

3、原因

xxxxMapper 上没有加上 @Repository 注解,不能被 Spring 识别注入。

类似组件注解,在不同的类名上要规范使用:

@Repository:代表dao层

@Component:这个惯用实体层

@Service : 这个用于service层

@Controller : 这个用于Controller

配上以上注解自自动装配时@Autowired 才不会报找不到错误

这四个注解的功能都是一样的,都是代表某个类注册到Spring中,装配到Bean中

4、解决方案

xxxxMapper 上没有加上 @Repository 即可。

posted @ 2022-06-07 20:36  Code7Rain  阅读(412)  评论(0)    收藏  举报