• 获取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
  • 相关阅读:
    2017/3/27 morning
    2017/3/24 afternoon
    2017/3/24 morning
    2017/3/21 afternoon
    2017/3/21 morning
    2017/3/20 afternoon
    2017/3/20 morning
    2017/3/16 afternoon
    2017/3/16 morning
    2017/3/15afternoon
  • 原文地址:https://www.cnblogs.com/wuyouwei/p/10955507.html
Copyright © 2020-2023  润新知