开发者

Spring @Controllers declared in the root application context

开发者 https://www.devze.com 2023-04-12 00:13 出处:网络
Spring web applications have two context - the web co开发者_C百科ntext (child) and the root context (parent). If @Controller beans are defined in dispatcher-servlet.xml (the web context) everything is

Spring web applications have two context - the web co开发者_C百科ntext (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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号