@MapperScan和@ComponentScan 您所在的位置:网站首页 componentscan和mapperscan @MapperScan和@ComponentScan

@MapperScan和@ComponentScan

2024-01-20 14:00| 来源: 网络整理| 查看: 265

这两天新开一个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代码如下

WeChatDao

启动类代码如下

启动类

这妥妥的不科学啊,在同一个路径包下的其它service和controller都扫描注册成功了,独独@Repository失败。后经研究发现,使用@MapperScan代替@ComponentScan就能解决这个问题。

解决后

他们的区别如下: @ComponentScan是组件扫描注解,用来扫描@Controller @Service @Repository @Component这类,主要就是从扫描路径中找出标志了需要装配的类到Spring容器中

@MapperScan 是扫描mapper类的注解



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有