Description:
Field resArticleClassifyService in com.wenwen.blog.controller.admin.AdminArticleController required a single bean, but 2 were found:
- resArticleClassifyServiceImpl: defined in file [D:learnlifelife-blogtargetclassescomwenwenblogserviceimplResArticleClassifyServiceImpl.class]
- IResArticleClassifyService: defined in file [D:learnlifelife-blogtargetclassescomwenwenblogserviceIResArticleClassifyService.class]
0、写在前面
编写程序时,SpringBoot项目使用@SpringBootApplication、@MapperScan(“com.wenwen”)、@Controller和@Service注解
运行后报了这个错误
造成原因:
在controller引用serIve
@RestController
public class IndexController {
@Autowired
UserMapper userMapper;
@Autowired
IIndexService indexService;
@ApiOperation(value = "分类列表")
@GetMapping("/listClassify")
public ResponseListBase<String> listClassify(@RequestParam("userId") Integer userId){
return indexService.listClassify(userId);
}
}
service
中只使用了@Service,
IndexServiceImpl继承了IIndexService。调用indexServiceImpl中的方法
1、问题描述
引起的原因
2、解决
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
在实现类上标记一个默认注入注解@Primary
@Service
@Primary
public class IndexServiceImpl implements IIndexService {
最后
以上就是懦弱柜子最近收集整理的关于required a single bean, but 2 were found0、写在前面1、问题描述2、解决的全部内容,更多相关required内容请搜索靠谱客的其他文章。
发表评论 取消回复