Spring Mapping XML Handler

is it possible to specify the type of request method in SimpleUrlHandlerMapping or other XMLMapper handler via XML config? And calling the controller method too ??

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="order" value="1" />
   <property name="mappings">
     <props>
       <prop key="/welcome.htm" >clinicController</prop> 
       // something like <prop key="/welcome.htm" method="GET" controllerMethod="someMethod1 ..."
       <prop key="/vets.htm">clinicController</prop>  
       // something like <prop key="/vets.htm" method=PUT method="GET" controllerMethod="someMethod2 ..."
       <prop key="/meds.htm">clinicController</prop>  
       // something like <prop key="/meds.htm" method=POST method="GET" controllerMethod="someMethod3 ..."
     </props>
   </property>
</bean>

      

I am trying to find an answer, but I cannot find anything. I prefer to use XML configuration instead of annotation. But in annotation it is possible to use

@RequestMapping(value = "/welcome.htm", method = RequestMethod.GET)

      

+3


source to share


1 answer


You can not. SimpleUrlHandlerMapping is actually a legacy spring HandlerMapping implementation that was mostly useful for the old pre-2.5 mvc model. In this model, you had to extend certain controller classes, so the behavior was preconfigured (i.e., a standard workflow was applied to one controller type for each request). In other words, the GET or POST method was handled by predefined abstract or concrete methods that you could override. Hence, this pattern made the method type mapping redundant.

Before spring 3.1, you could even mix the two patterns to some extent. One could use SimpleUrlHandlerMapping to map the controller beans to some url prefix and further refine on the method type (or the rest of the url or parameters, etc.) regarding controller methods using annotations. This was possible because the bean and method mappings were done at different points. spring link to this explicitly:



Prior to spring 3.1, method-type request mappings were explored in two separate steps - the DefaultAnnotationHandlerMapping controller was selected first and the actual method to call was narrowed down to the second using AnnotationMethodHandlerAdapter. With the new support classes in spring 3.1, RequestMappingHandlerMapping is the only place where a solution needs to handle a request. Think of controllers as a set of unique endpoints with mappings for each method, derived from the type and method level @RequestMapping information.

In general, annotation driven mvc today is preferred and more flexible than the old style. Since IDE-like STSs now provide ways to test all handler mappings in a single view, I don't see any real drawback. Of course, this is just my opinion, so you can safely ignore it, but at least weigh the benefits of each approach.

0


source







All Articles