public String init(HttpServletRequest request, HttpServletResponse response){ List<String> uList = new ArrayList<String>();//存储所有url集合 WebApplicationContext wac = (WebApplicationContext) request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);//获取上下文对象 RequestMappingHandlerMapping bean = wac.getBean(RequestMappingHandlerMapping.class);//通过上下文对象获取RequestMappingHandlerMapping实例对象 Map<RequestMappingInfo, HandlerMethod> handlerMethods = bean.getHandlerMethods(); for (RequestMappingInfo rmi : handlerMethods.keySet()) { PatternsRequestCondition prc = rmi.getPatternsCondition(); Set<String> patterns = prc.getPatterns(); for (String uStr : patterns) { uList.add(uStr); } } }