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。