Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @Controllers declared in the root application context

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.

like image 987
Bozho Avatar asked Oct 07 '11 14:10

Bozho


1 Answers

DefaultAnnotationHandlerMapping has a detectHandlersInAncestorContexts property that enables the desired behaviour.

like image 121
axtavt Avatar answered Sep 25 '22 15:09

axtavt