我是靠谱客的博主 懦弱柜子,最近开发中收集的这篇文章主要介绍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 a single bean, but 2 were found0、写在前面1、问题描述2、解决所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部