这两天搭建自己的毕设项目框架,遇到一个超级奇怪的问题,用的是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
项目结构如下: