Skip to content

Provide public methods to register and un-register handler method mappings [SPR-11541] #16166

@spring-projects-issues

Description

@spring-projects-issues

cemo koc opened SPR-11541 and commented

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);
   }
}

Affects: 3.2.8, 4.0.2

Issue Links:

0 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions