zoukankan      html  css  js  c++  java
  • 获取spring中所有定义了的requestMapping信息

      获取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()));
      }
    View Code
      @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
  • 相关阅读:
    hdu5358 推公式+在一个区间内的尺取+枚举法
    poj3349 散列表(hash)
    hdu3282 链表或者对顶堆
    hdu5178 尺取
    hdu5672 尺取
    hdu3244完全背包+二分答案 留坑
    hdu5256 二分求LIS+思维
    hdu5646数学构造+二分
    hdu4190 二分答案
    Python中Scapy网络嗅探模块的使用
  • 原文地址:https://www.cnblogs.com/wuyouwei/p/10955507.html
Copyright © 2011-2022 走看看