IDEA 解决Could not autowire. No beans of 'XXX' type found.

IDEA 解决Could not autowire. No beans of ‘XXX’ type found.

问题如下图所示:
在这里插入图片描述
报错:Could not autowire. No beans of ‘ExamLessonService’ type found.

解决方案:在对应的Mapper的加上@Repository
和对应service的加上@Service

import java.util.List;
//@Mapper
@Repository
public interface ExamLessonMapper {
    /**
     *
     * 查询所有考试课程数据
     */

    public List<ExamLesson> findExamLesson();
}
    
//service
@Service
public class ExamLessonServiceImpl implements ExamLessonService {
    //属性注入
    @Autowired
    private ExamLessonMapper examLessonMapper;


这样问题就解决了
在这里插入图片描述
总结:spring中的注解,@Repository用于标注数据访问组件,即DAO组件。
@Service是一个注解,告诉spring创建一个实现类的实例。简单来说就是不用再spring里配置bean。

发布了21 篇原创文章 · 获赞 9 · 访问量 4509

猜你喜欢

转载自blog.csdn.net/qq_36470898/article/details/98793813