获取spring中所有定义了的requestMapping信息

  获取spring中所有定义了的requestMapping信息

  前置条件:

  所在bean实现ApplicationContextAware接口

  拥有属性private Set<String> requestMappings = new HashSet<>(500);

  

  实现过程:

  

获取spring中所有定义了的requestMapping信息
@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()));
  }
View Code
获取spring中所有定义了的requestMapping信息
  @GetMapping("obtain.request.mapping")
  public R obtainRequestMapping() {
    return R.success(requestMappings);
  }
View Code

 

  如果拿不到bean用

AbstractHandlerMethodMapping<RequestMappingInfo> methodMapping = (AbstractHandlerMethodMapping<RequestMappingInfo>) applicationContext.getBean(RequestMappingHandlerMapping.class.getName());

获取:{{url}}/obtain.request.mapping

获取spring中所有定义了的requestMapping信息

上一篇:Android 中的 wakelock


下一篇:react+axios