获取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

相关文章:

  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-06-28
猜你喜欢
  • 2021-11-02
  • 2021-12-23
  • 2019-05-31
  • 2021-07-06
  • 2022-12-23
  • 2021-12-02
  • 2021-10-21
相关资源
相似解决方案