I have a number of controllers with various request handlers in my Spring 3.x project (all annotation-based, using @Controller
and @RequestMapping
).
Currently, the application context just defines DefaultAnnotationHandlerMapping
and AnnotationMethodHandlerAdapter
beans. If I understand it correctly, these could also be replaced with <mvc:annotation-driven/>
.
The existing controllers mostly fill a model that is passed in via the parameters and then return a view name as a string. The mapping is done by standard DefaultRequestToViewNameTranslator
and InternalResourceViewResolver
beans.
Now I would like to introduce a new controller, which needs an HttpMessageConverter
(it will be a MappingJacksonHttpMessageConverter
) and a HandlerExceptionResolver
specific to this controller.
The existing controllers should not be affected in any way. Neither should their requests and responses be converted by the message converter, nor should any exceptions be handled by the exception resolver.
Is there a way to do this without dropping annotation-based configuration for the new controller? Is there a way to set the message converter and the exception resolver specifically for one controller, without giving up the URL routing based on @RequestMapping
?
Or is there maybe a way to choose a converter/resolver configuration using an annotation on the controller?
If not, what's the next best approach to do this?