這是在用springboot時遇到的errorspring
Description:springboot
Field ud in com.yjj.service.impl.UserServiceImpl required a bean of type 'com.yjj.dao.UserDao' that could not be found.mybatis
Action:app
Consider defining a bean of type 'com.yjj.dao.UserDao' in your configuration.ide
緣由:ui
我找到的一種緣由是在mappers文件夾下的mapper.xml文件沒有掃到com.yjj.dao這個包spa
因此要在Application(啓動類)上加上code
@MapperScan("com.yjj.dao")註解
代碼以下:
package com.yjj.bootdemo01; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = {"com.yjj.dao","com.yjj.service","com.yjj.controller"}) @MapperScan("com.yjj.dao") public class Bootdemo01Application { public static void main(String[] args) { SpringApplication.run(Bootdemo01Application.class, args); } }