概述
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、解决所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复