Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.xx.xx.core.mapper.Mapper<?>' available: expected single matching bean but found 3: xx1Mapper,xx2Mapper,xx3Mapper
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1285)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:521)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:497)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:650)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:228)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:318)
... 34 common frames omitted
新建的项目引入了tk.mybatis,创建了通用mapper,其他业务mapper继承了这个通用mapper,项目启动报错
NoUniqueBeanDefinitionException: No qualifying bean of type 'com.xx.xx.core.mapper.BaseDao<?>' available: expected single matching bean but found 6:
原因,通用service中注入mapper使用的@Resource
解决方法:@Resource替换为@Autowired
- @Autowired:先通过类型找,然后通过名称找,@Resource:先通过名称找,然后通过类型找