目录

Java NoUniqueBeanDefinitionException

目录

在使用Spring Web + Mybatis-plus + MybatisX插件,创建Java工程后,启动时总是报不唯一的bean,反复检查了几遍,也没有找到问题。

1
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'com.coding.generator.service.ApiNotesService' available: expected single matching bean but found 2: apiNotesServiceImpl,apiNotesService

经过搜索,找到了2种解决方法

  1. 按名字匹配注入
    1
    2
    
    @Resource(name = "apiNotesServiceImpl")
    private ApiNotesService notesService;
    
    或者
    1
    2
    3
    
    @Autowired
    @Qualifier("apiNotesServiceImpl")
    private ApiNotesService notesService;
    
  2. 提供准确的@MapperScan路径
    1
    
    @MapperScan("com.coding.generator.mapper")