I have two controller classes with the same name but in different packages under my Spring MVC application but when compiling the application refuses to run on server giving me an error.
Any chance anyone knows how to allow having same controller class name in two (different packages) under a Spring MVC project?
use value attribute of controller annotation
@Controller("controller1")
and
@Controller("controller2")
To add to Bassem's answer,
If you had two controllers in 2 packages:
pkg1
pkg2
You could use the @Controller
annotation:
@Controller("pkg1 myController")
@Controller("pkg2 myController")
So that way it is more organized. You also cannot have the same value in your @Controller("THIS VALUE")
.
So if you had:
pkg1 - myController1 - myController2
You can not have them both have
@Controller("pkg1")
Instead you could use @Controller("pkg1 myController1)
to avoid collisions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With