springspring-mvcpackagecomponent-scan

How can I specify into the Spring XML configuration to perform the component-scan on two different packages?


I am pretty new in Spring MVC and I have the following problem.

In the application on which I am working I have 2 controllers classes declared into two different packages.

So I am trying to specify into my XML configuration the second package that have to be scanned by the component scan setting.

So if I only have this setting works fine (but I scan only a package):

<context:component-scan base-package="it.mycompmany.myproject.registrazione"></context:component-scan>

But if I try to specify that have to be scanned two different package, in this way:

<!-- Controller -->
<context:component-scan base-package="it.mycompmany.myproject.registrazione">
</context:component-scan>

<context:component-scan base-package="it.mycompmany.myproject.login>
</context:component-scan>

Eclipse give me error on the second component-scan setting tag:

The value of attribute "base-package" associated with an element type "context:component-scan" must not contain the '<' character.

What is the problem? How can I correctly specify that I have to scan two different packages? What am I missing?


Solution

  • You can specify multiple packages using comma

    <context:component-scan base-package="it.mycompmany.myproject.registrazione,it.mycompmany.myproject.login">
    </context:component-scan>