如果您使用的是Spring
3.1,则此handlerMapping组件是RequestMappingHandlerMapping的一个实例,您可以通过以下方式查询以找到handlerMappedMethods和关联的控制器(如果您使用的是Spring的较旧版本,则应该能够使用类似的方法):
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;@Controllerpublic class EndpointDocController { private final RequestMappingHandlerMapping handlerMapping; @Autowired public EndpointDocController(RequestMappingHandlerMapping handlerMapping) { this.handlerMapping = handlerMapping; } @RequestMapping(value="/endpointdoc", method=RequestMethod.GET) public void show(Model model) { model.addAttribute("handlerMethods", this.handlerMapping.getHandlerMethods()); } }我已在此网址http://biju-allandsundry.blogspot.com/2012/03/endpoint-documentation-
controller-for.html上提供了更多详细信息
这基于Spring Source的Rossen Stoyanchev在Spring 3.1上的演示。



