从Spring
3.1开始,存在类
RequestMappingHandlerMapping,它提供有关
RequestMappingInfo@Controller类的映射()的信息。
@Autowiredprivate RequestMappingHandlerMapping requestMappingHandlerMapping;@PostConstructpublic void init() { Map<RequestMappingInfo, HandlerMethod> handlerMethods = this.requestMappingHandlerMapping.getHandlerMethods(); for(Entry<RequestMappingInfo, HandlerMethod> item : handlerMethods.entrySet()) { RequestMappingInfo mapping = item.getKey(); HandlerMethod method = item.getValue(); for (String urlPattern : mapping.getPatternsCondition().getPatterns()) { System.out.println( method.getBeanType().getName() + "#" + method.getMethod().getName() + " <-- " + urlPattern); if (urlPattern.equals("some specific url")) { //add to list of matching METHODS } } } }在定义控制器的spring上下文中定义此bean非常重要。



