Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-11541

Provide public methods to register and un-register handler method mappings

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.2.8, 4.0.2
    • Fix Version/s: 4.2 RC1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      We are heavily using Spring MVC and currently we had to duplicated a fair amount codes to provide necessary functionalities. We are providing redirection mappings by database. At runtime we periodically checking for any kind of operation such deletion or insertion and want to register them by RequestMappingHandlerMapping.

      Spring's RequestMapping is nice but does not provide easy way to provide addition or deletion of RequestMapping's. In order to add a new mapping, RequestMappingHandlerMapping has to be extended as this:

      public class RequestMappingInfoAppendableHandlerMapping extends RequestMappingHandlerMapping {
      
         @Override
         @Override
         public void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) {
            super.registerHandlerMethod(handler, method, mapping);
         }
      }
      

      I still did not find a beautiful way to unregistering mappings. What I am suggesting:

      Please provide necessary util classes and public methods to registering and unregistering request mappings.

      By the way I have already tried other HandlerMapping implementations but I do not want to change priority because of the performance cost. Also a custom HandlerMapping after RequestMappingHandlerMapping is not capable of handling because of our mappings at RequestMappingHandlerMapping.

      Edit:

      I had also implemented a very basic utility function for creating new MappingInfo's. I believe that such convenient methods will be very useful. A Builder can be great as well.

      public final class RequestMappingInfoUtils {
      
         public static RequestMappingInfo newInstance(String[] urls){
            return newInstance(urls, RequestMethod.GET);
         }
      
         public static RequestMappingInfo newInstance(String[] urls, RequestMethod requestMethod){
            return new RequestMappingInfo(new PatternsRequestCondition(urls),
                                          new RequestMethodsRequestCondition(requestMethod),
                                          null,
                                          null,
                                          null,
                                          null,
                                          null);
         }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstoya05-aop Rossen Stoyanchev
              Reporter:
              cemokoc cemo koc
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 24 weeks, 5 days ago