小编典典

上下文中的多个包:component-scan,spring config

all

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

我努力了

<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:

阅读 101

收藏
2022-07-14

共1个答案

小编典典

以下方法是正确的:

<context:component-scan base-package="x.y.z.service, x.y.z.controller" />

请注意,错误抱怨x.y.z.dao.daoservice.LoginDAO,它不在上面提到的包中,也许您忘记添加它:

<context:component-scan base-package="x.y.z.service, x.y.z.controller, x.y.z.dao" />
2022-07-14