Spring @Controllers declared in the root context of the application

Spring web applications have two contexts: web context (child) and root context (parent). If @Controller beans are defined in dispatcher-servlet.xml (web context), everything is fine.

But if the beans controller is 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 a controller, the path was not found.

The question is this: how to make controller mappings parsable regardless of where beans are defined.

PS I know that I can move ads into a child’s context, but I don’t want to do this for reasons beyond the scope of this question.

+6
source share
1 answer

DefaultAnnotationHandlerMapping has a detectHandlersInAncestorContexts property that allows the desired behavior.

+5
source

Source: https://habr.com/ru/post/898835/


All Articles