IDEA报错:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxxxImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.smile.cms.mapper.xxxxMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
报错原因分析:
因为不能扫描到mapper文件,需要在启动类上加@MapperScan
@MapperScan(“mapper的路径”)
注解来指定需要扫描的mapper文件的路径
不然不能够找到
@SpringBootApplication
@Api(description = "banner管理")
@ComponentScan(basePackages = {"com.smile"}) //会扫描所有这个路径下的类,包含父类中的这个路径
@MapperScan("com.smile.cms.mapper")
public class CmsApplication {
public static void main(String[] args) {
SpringApplication.run(CmsApplication.class,args);
}
}