0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • 1
    The `base-package` attribute takes a comma separated list of values. Just use `base-package="it.mycompmany.myproject.registrazione,it.mycompmany.myproject.login"`. Your code fails btw because the second one misses a `"` on the end. – M. Deinum Apr 12 '16 at 11:13
  • Is the closing comma in one of the `context:component-scan` missing in your real code too? – kryger Apr 26 '16 at 09:47
  • Possible duplicate of [multiple packages in context:component-scan, spring config](http://stackoverflow.com/questions/5269450/multiple-packages-in-contextcomponent-scan-spring-config) – kryger Apr 26 '16 at 10:04

2 Answers2

1

You can specify multiple packages using comma

<context:component-scan base-package="it.mycompmany.myproject.registrazione,it.mycompmany.myproject.login">
</context:component-scan>
Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112
-2

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>
Grim
  • 1,938
  • 10
  • 56
  • 123