Shams Shams - 2 years ago 484
Java Question

multiple packages in context:component-scan, spring config

How can I add multiple packages in spring-servlet.xml file in


I have tried

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

but got error:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [x.y.z.dao.daoservice.LoginDAO] found for dependency:

Answer Source

The following approach is correct:

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

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" /> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download