@MapperScan和@ComponentScan
程序员文章站
2022-03-10 17:07:43
这两天新开一个springboot + mybatis项目,启动时报错提示***************************APPLICATION FAILED TO START***************************Description:Parameter 0 of constructor in com.xxx.xxx.wechat.service.impl.WeChatServiceImpl required a bean of type 'com.xxx.xxx.w...
这两天新开一个springboot + mybatis项目,启动时报错提示
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.xxx.xxx.wechat.service.impl.WeChatServiceImpl required a bean of type 'com.xxx.xxx.wechat.dao.WeChatDao' that could not be found.
Action:
Consider defining a bean of type 'com.xxx.xxx.wechat.dao.WeChatDao' in your configuration.
Process finished with exit code 1
dao代码如下
启动类代码如下
这妥妥的不科学啊,在同一个路径包下的其它service和controller都扫描注册成功了,独独@Repository失败。后经研究发现,使用@MapperScan代替@ComponentScan就能解决这个问题。
他们的区别如下:
@ComponentScan是组件扫描注解,用来扫描@Controller @Service @Repository @Component这类,主要就是从扫描路径中找出标志了需要装配的类到Spring容器中
@MapperScan 是扫描mapper类的注解
本文地址:https://blog.csdn.net/u010044936/article/details/112002503