1.最近在跟着视频学习淘淘商城项目,在第五天时,出现了这样的错误:
该项目用的是maven管理,具体错误为:
1)Error creating bean with name 'itemCatController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.taotao.rest.service.ItemCatService com.taotao.rest.controller.ItemCatController.itemCatService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taotao.rest.service.ItemCatService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
2)org.springframework.beans.factory.BeanCreationException
意思找到不到对应的bean,bean注入失败,即service注入controller失败。
2.后来经过网上查找方法,才发现是自己对应包的注解扫描包配置结构出现错误,具体如下:
对应的应该是箭头标注的地方,
而我配置的错误方法如下:把其具体实现的service包是com.taotao.rest.serviceImpl,配置成了com.taotao.rest.service
究其原因,原视频开发是用ecplise开发,而自己用的是myecplise,创建包结构展开方式不同,myecplise创建包结构是分开的,而ecplise创建的service和其实现类serviceImpl都是在com.taotao.service包下,这样只看视频操作就可能出错,以后要多注意。