叫我joker就好啦 2021-09-20 14:24 采纳率: 0%
浏览 238

添加@service注解报错,不加又注入不了的问题

这两天搭建自己的毕设项目框架,遇到一个超级奇怪的问题,用的是spring boot + Thymeleaf + mybatis-plus,数据库是MySQL。
业务层都是用mybatis-plus自动生成的,结果问题就出现了,报错信息如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-20 14:05:42.551 ERROR 5516 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'articleServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.blogshare.article.mapper.ArticleMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.blogshare.article.mapper.ArticleMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

实现类:

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

}

这个报错第一天找了四个多小时,最常见的就是没加@service注解,但是自动生成的实现类必然加了的,然后还有各种@mapper注解啦,说xml有问题啦,路径扫描问题啦,我都一一排查过都没有问题,然后我把@service注解删了,奇迹发生了,他不报错了,但是没有这个注解我controller层注入不了service

项目结构如下:

img

  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-09-20 14:29
    关注

    是因为ArticleMapper没有注入,导致其他类注入失败。

    评论

报告相同问题?

问题事件

  • 修改了问题 9月20日
  • 修改了问题 9月20日
  • 创建了问题 9月20日

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100