一尘不染

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

java

如何在context:component-scanelement的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:

阅读 182

收藏
2020-09-08

共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" />
2020-09-08