Spring web applications have two context - the web context (child) and the root context (parent). If @Controller
beans are defined in dispatcher-servlet.xml
(the web context) everything is fine.
But if the controller beans are defined in the parent context (applicationContext.xml
), then the controllers are not recognized - i.e. their mappings are not configured, so when you try to open /foo/bar
defined in such controller, the path is not found.
The question is: how to make the controller mappings to be parsed no matter where the beans are defined.
P.S. I know I can move the declarations to the child context, but I don't want to do that for reasons beyond the scope of this question.
DefaultAnnotationHandlerMapping
has a detectHandlersInAncestorContexts
property that enables the desired behaviour.
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