Is it possible to dynamically set RequestMappings in Spring MVC?

Spring MVC performs URL mappings using implementations of the HandlerMapping interface. The ones usually used out of the box are the default implementations, namely SimpleUrlHandlerMapping BeanNameUrlHandlerMapping and DefaultAnnotationHandlerMapping .

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I've been using Spring MVC for three months now. I was considering a good way to dynamically add RequestMapping. This comes from the necessity to put controller parts in a library and then add them dinamically.

Anyway, the only way I can think of is to declare a controller like this: @Controller @RequestMapping("/mypage") public class MyController { @RequestMapping(method = RequestMethod. GET) public ModelAndView mainHandler(HttpServletRequest req) { return handleTheRest(req); } } Which is no good because basically I'm not using Spring. Then I cannot use form binding, annotations etc.. I'd like to add requestMappings dynamically to methods of classes that could be annotated like usual MVC controllers, with autobinding, so that I could avoid processing HttpServletRequest manually.

Any ideas? } spring-mvc link|improve this question asked Apr 22 '11 at 18:09gotch41,638835 66% accept rate.

Spring MVC performs URL mappings using implementations of the HandlerMapping interface. The ones usually used out of the box are the default implementations, namely SimpleUrlHandlerMapping, BeanNameUrlHandlerMapping and DefaultAnnotationHandlerMapping. If you want to implement your own mapping mechanism, this is fairly easy to do - just implement that interface (or, perhaps more likely, extend AbstractUrlHandlerMapping), declare the class as a bean in your context, and it will be consulted by DispatcherServlet when a request needs to be mapped.

Note that you can have as many HandlerMapping implementations as you like in the one context. They will be consulted in turn until one of them has a match.

Thanks Skaff, you always give great tips. Anyway, how do I manipulate the context by code, I mean, is there a way to dynamically add an HandlerMapping bean or any other bean? – gotch4 Apr 23 '11 at 9:01 @gotch4: You don't need to dynamically add a HandlerMapping.

You configure one custom HandlerMapping, and then dynamically add mappings to it. Since you're writing the HandlerMapping yourself, how that works is up to you. – skaffman Apr 23 '11 at 9:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions