上下文中的多个包:组件扫描,弹簧配置 [英] multiple packages in context:component-scan, spring config
本文介绍了上下文中的多个包:组件扫描,弹簧配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 context:component-scan
元素的 spring-servlet.xml 文件中添加多个包?
How can I add multiple packages in spring-servlet.xml file in context:component-scan
element?
我试过了
<context:component-scan base-package="z.y.z.service" base-package="x.y.z.controller" />
和
<context:component-scan base-package="x.y.z.service, x.y.z.controller" />
和
<context:component-scan base-package="x.y.z.service" />
<context:component-scan base-package="x.y.z.controller" />
但出现错误:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [x.y.z.dao.daoservice.LoginDAO] found for dependency:
推荐答案
以下做法是正确的:
<context:component-scan base-package="x.y.z.service, x.y.z.controller" />
注意,错误提示的是x.y.z.dao.daoservice.LoginDAO
,它不在上面提到的包中,可能是你忘记添加了:
Note that the error complains about x.y.z.dao.daoservice.LoginDAO
, which is not in the packages mentioned above, perhaps you forgot to add it:
<context:component-scan base-package="x.y.z.service, x.y.z.controller, x.y.z.dao" />
这篇关于上下文中的多个包:组件扫描,弹簧配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文