我是靠谱客的博主 懦弱柜子,这篇文章主要介绍required a single bean, but 2 were found0、写在前面1、问题描述2、解决,现在分享给大家,希望可以做个参考。

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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(101)

评论列表共有 0 条评论

立即
投稿
返回
顶部