Reputation: 169
I am using Spring-MVC's MultiActionController coupled with PropertiesMethodNameResolver to map the URLs to apppriate methods of my Controller class. The requirement is map all the urls containing a particular word 'abc' to one method, 'xyz' to the second method and so on. All the urls can be arbitrarity long and hence have to be matched using regex patterns, all the urls end with the same extension and all the remaining urls should map to the default method. Hence we are using the following:
<bean id="paramMultiController" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController">
<property name="methodNameResolver">
<ref bean="propsResolver" />
</property>
<property name="delegate">
<ref bean="methodsContainer" />
</property>
</bean>
<bean id="methodsContainer" class="com.abc.controller.MethodsContainer"/>
<bean id="propsResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/">defaultMethod</prop>
<prop key="/**/abc.ext">methodAbc</prop>
<prop key="/def/**/*.ext">methodDef</prop>
<prop key="/xyz/**/*.ext">methodXyz</prop>
<prop key="/**/ijk/**/*.ext">makeIjk</prop>
<prop key="/**/*.ext">defaultMethod</prop>
</props>
</property>
</bean>
This was working till we were using Spring-2.5, but recently started having issues when we upgrade to Spring-4.0. The reason for the issue as I found-out was a code change in PropertiesMethodNameResolver from Spring-2.5 to Spring-3.0. Earlier PropertiesMethodNameResolver was using Iterators to iterate over the defined mappings and was matching it against the requested URL, but Spring-3.0 switched to start using Enumerator and the order was jumbled, causing the urls to mostly match against defaultMethod.
Can you please suggest a solution to this. We want the urls to be processed(matched) in the sequence defined by us in the configuration file. Please note we don't want to use annotations, because we have too many URL's mapping and using the annotations will spread the URL mappings to go to many of the classes, making it difficult to consolidate and manage mappings.
Upvotes: 0
Views: 301
Reputation: 4024
You can override the protected method getHandlerMethodNameForUrlPath
of class PropertiesMethodNameResolver
and implement the desired behavior.
Upvotes: 1