1.报错信息
Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lei.dao.StudentMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2.dao层代码
@Mapper
public interface DepartDao extends BaseMapper<Depart> {
}
3.测试代码
@RunWith(SpringRunner.class)
@SpringBootTest()
class DepartDaoTest {
@Autowired
DepartDao departDao;
@Test
public void testSelect() {
System.out.println("111");
}
}
4.springboot启动类(解决办法:@MapperScan(basePackages = {"xxx.xxx.xxx"}))
@SpringBootApplication
@MapperScan(basePackages = {"xxx.xxx.xxx"})
public class Class4MybatisApplication {
public static void main(String[] args) {
SpringApplication.run(Class4MybatisApplication.class, args);
}
}