本文介绍了上下文中的多个包:component-scan,spring config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在上下文中的spring-servlet.xml文件中添加多个包:component-scan 元素?

我试过了

<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" />

注意错误抱怨 xyzdao.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" />

这篇关于上下文中的多个包:component-scan,spring config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 22:25