I am using Spring 3.1 MVC and in one of the request I get parameter which is URL.
e.g. http:/myapp/controllername?url=someurl
I need to find out in my controller method whether some URL is configured in my application.
I tried using RequestMappingHandlerMapping instance to get
Map<RequestMappingInfo, HandlerMethod> handlerMethods = handlerMapping.getHandlerMethods();
But I have a string which is URL, I will need to create a RequestMappingInfo object out of this to look up in this map, which doesn’t have any constructor based on just URL.
How to find whether an URL mapping exists in spring mvc 3.1 using code in a controller?
You can use requestMappingInfo.getPatternsCondition() to check the mapping path; and it has toString method for you to compare with your url string.
Example: For url
http://mydomain/test/abcthe above condition should be asif("[/test/abc]".equals(rm.getPatternsCondition().toString()))I believe you have already autowired handlerMapping object in your controller, as below