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