项目场景:
个人解决方法的简单记载,吸取一下教训,一天忘记
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘testallServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.syp.bpboot.testall.mapper.TestallMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
问题描述:
springboot 项目集成了mybatisplus之后报错,报错:
No qualifying bean of type ‘xxx.xxx.xxx.xxx’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
原因分析:
这是因为不能扫描到mapper文件,测试需要在启动类上加
@MapperScan
注解来指定需要扫描的mapper文件的路径
不然不能够找到
解决方案:
//需要扫描的mapper文件夹
@MapperScan("com.syp.bpboot.testall.mapper")
@SpringBootApplication
public class BpbootApplication {
public static void main(String[] args) {
SpringApplication.run(BpbootApplication.class, args);
}
}