SpringMVC 中获取所有的路由配置。
ApplicationContext context = TMSContextLookup.getApplicationContext(); String[] controllerList = context.getBeanNamesForAnnotation(Controller.class); for(String name : controllerList){ try { Object bean = context.getBean(name); String preFix = ""; RequestMapping clazzRequestMapping = bean.getClass().getAnnotation(RequestMapping.class); if (clazzRequestMapping!=null && !TMSUtil.isEmpty(clazzRequestMapping.value())){ preFix = clazzRequestMapping.value()[0]; } Method[] method = bean.getClass().getDeclaredMethods(); if (method!=null){ for (Method m :method){ RequestMapping mRequestMapping = m.getAnnotation(RequestMapping.class); if (mRequestMapping!=null && !TMSUtil.isEmpty(mRequestMapping.value())){ String path = mRequestMapping.value()[0]; System.out.println(preFix + "/" + path); } } } }catch (Exception e){ System.out.println(e.getMessage()); } }