获取spring中所有定义了的requestMapping信息
前置条件:
所在bean实现ApplicationContextAware接口
拥有属性private Set<String> requestMappings = new HashSet<>(500);
实现过程:
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping = (AbstractHandlerMethodMapping<RequestMappingInfo>) applicationContext.getBean("requestMappingHandlerMapping"); Map<RequestMappingInfo, HandlerMethod> mapRet = methodMapping.getHandlerMethods(); mapRet.keySet().forEach(requestMappingInfo -> requestMappings.add(requestMappingInfo.toString())); }
@GetMapping("obtain.request.mapping") public R obtainRequestMapping() { return R.success(requestMappings); }
如果拿不到bean用
AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping = (AbstractHandlerMethodMapping<RequestMappingInfo>) applicationContext.getBean(RequestMappingHandlerMapping.class.getName());
获取:{{url}}/obtain.request.mapping