添加多个<context:component-scan base-package/>总是报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appArticleInfoController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.icekredit.nanjing.service.impl.AppArticleInfoServiceImpl com.icekredit.nanjing.controller.AppArticleInfoController.appArticleInfoService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appArticleInfoServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.icekredit.util.CommonUtil com.icekredit.nanjing.service.impl.AppArticleInfoServiceImpl.commonUtil; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.icekredit.util.CommonUtil] 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)}

我的spring-mvc.xml

<context:component-scan base-package="com.***.***.controller"/>
<context:component-scan base-package="com.***.***.service.impl"/>
<context:component-scan base-package="com.***.***.service"/>
<context:component-scan base-package="com.***.***.mapper"/>
<context:component-scan base-package="com.***.***.controller"/>
<context:component-scan base-package="com.***.***.service.impl"/>
<context:component-scan base-package="com.***.***.service"/>
<context:component-scan base-package="com.***.***.mapper"/>

![图片说明](https://img-ask.csdn.net/upload/201608/24/1472031980_843879.jpg)

2个回答

它已经提示你了, 看这里 NoSuchBeanDefinitionException:
No qualifying bean of type [com.icekredit.util.CommonUtil] found for dependency

没有这样的 bean 异常, base-package 再添加个范围:

 <context:component-scan base-package= "com.*.*.CommonUtil"/>

org.springframework.beans.factory.NoSuchBeanDefinitionException:
Spring对象application.xml配置:少了bean对象,无法自动注释

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐