No qualifying bean of type报错问题处理

本文详细解析了Noqualifyingbeanoftype错误的原因及解决方法,包括配置serviceImpl扫描路径、使用@Service注解以及确保Controller中正确引用Service接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

No qualifying bean of type报错问题处理

报错问题:

No qualifying bean of type [com.yipingou.service.impl.ItemCatServiceImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

解决方法:
  1. 添加serviceImpl扫描的路径
<!--
	扫描包:加载service实现类
-->
<context:component-scan base-package="com.yipingou.service"/>
  1. 把现实类和服务接口放在一个包下统一扫描。
    在这里插入图片描述
  2. 在实现类中加上注解
@Service
public class ItemCatServiceImpl implements ItemCatService {}
  1. 最后也是最重要的细节。
@Controller
public class ItemController {
	//在Controller中,创建service层对象的类型必须用Service实现类的接口名(多态),不能用Service的实现类
	@Autowired
	private ItemService itemService;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值