首页 > 技术文章 > spring @MapperScan和@ComponentScan的区别

Shining-stars 2020-09-14 09:12 原文

区别

今天在撸SpringBoot的时候,突然对注解产生了混淆,@MapperScan和@ComponentScan都是扫描包,二者之间有什么区别呢?

首先,@ComponentScan是组件扫描注解,用来扫描@Controller  @Service  @Repository这类,主要就是定义扫描的路径从中找出标志了需要装配的类到Spring容器中

其次,@MapperScan 是扫描mapper类的注解,就不用在每个mapper类上加@MapperScan了

这两个注解是可以同时使用的。

https://blog.csdn.net/m0_37597572/article/details/82625631

 

@ComponentScan说明

https://blog.csdn.net/Lamb_IT/article/details/80918704

 

@MapperScan说明

https://blog.csdn.net/nba_linshuhao/article/details/82783454

推荐阅读