AndreaNobili
AndreaNobili

Reputation: 43047

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?

Upvotes: 0

Views: 123

Answers (2)

Karthik Prasad
Karthik Prasad

Reputation: 10034

You can specify multiple packages using comma

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

Upvotes: 1

Grim
Grim

Reputation: 2030

Change from

<!-- Controller -->
<context:component-scan base-package="it.istruzione.iam.ssum.registrazione">
</context:component-scan>

<context:component-scan base-package="it.istruzione.iam.ssum.login>
</context:component-scan>

to

<!-- Controller -->
<context:component-scan base-package="it.istruzione.iam.ssum.registrazione">
</context:component-scan>

<context:component-scan base-package="it.istruzione.iam.ssum.login">
</context:component-scan>

Upvotes: -2

Related Questions