mybatis-plus 生成代码错误 required a single bean, but 2 were found

时间:2025-03-20 11:02:51

在使用mybatis-plus 生成代码后,出现如下错误

Description:

Field courseInfoService in required a single bean, but 2 were found:
    - courseInfoServiceImpl: defined in file [D:\learning\xxxx\service\impl\]
    - ICourseInfoService: defined in file [D:\learning\xxxx\service\]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

 

后发现是使用@MapperScan注释是没有设置扫描范围,

改为@MapperScan(basePackages = "xxx.*.*.mapper")后成功运行