报错扫描出多个bean的问题
Description:
Field roleService in com.nms.yyterpmaster.core.adapter.impl.UserAdapterImpl required a single bean, but 2 were found:
- roleServiceImpl: defined in file [E:\java_Project_warehouse\yyt-erp-master\target\classes\com\nms\yyterpmaster\service\impl\RoleServiceImpl.class]
- IRoleService: defined in file [E:\java_Project_warehouse\yyt-erp-master\target\classes\com\nms\yyterpmaster\service\IRoleService.class]
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(basePackages = {"com.nums.*.*"})
这是用来扫描mapper文件的由于路径未标注具体mapper路径,这种路径会导致全表扫描,而service、controller等加了注解已经扫描了一遍,mapperscan又扫描了一遍,才会有重复的bean。
应该改为
@MapperScan(basePackages = {"com.nums.*.mapper"})