org.springframework.beans.factory.BeanCreationException

1 问题来源:

   最近在完成一个ssm项目中,遇到如下的问题:

   org.springframework.beans.factory.BeanCreationException_第1张图片

  使用的是maven管理,显示的错误是说: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)

翻译过来的说我没有在'itemCatController 类中注入成功 ItemCatService  一下就蒙圈了:明明注入了注解:(如下图)

    1  service层:

    org.springframework.beans.factory.BeanCreationException_第2张图片

    2  controller层

   org.springframework.beans.factory.BeanCreationException_第3张图片

    3  注解明显的注释了,并且在springmvc.xml中配置了注解驱动

   org.springframework.beans.factory.BeanCreationException_第4张图片

  经过认真的分析:原因如下:

 在分层结构中,我对注解的扫描包做了认真的分析:

org.springframework.beans.factory.BeanCreationException_第5张图片

上图中的红线对应的xml文件中应该扫描对应注解的类。

而实际中:我的扫描出现了偏差:

org.springframework.beans.factory.BeanCreationException_第6张图片

具体的错误:

org.springframework.beans.factory.BeanCreationException_第7张图片

应该修改为:

org.springframework.beans.factory.BeanCreationException_第8张图片


我的springmvc.xml 扫描是正确的。我也贴出来:

org.springframework.beans.factory.BeanCreationException_第9张图片

ok,这就是我的项目中遇到的问题,一起进步!

 

你可能感兴趣的:(ssm)