欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring boot(16) : 获取所有的uri

程序员文章站 2022-03-10 18:07:02
...

启动类中调用方法即可 

    public static void main(String[] args) throws Exception{
        ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
        test(run);
    }

    public static void test(ConfigurableApplicationContext run){
        RequestMappingHandlerMapping bean1 = run.getBean(RequestMappingHandlerMapping.class);
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = bean1.getHandlerMethods();

        handlerMethods.forEach((k,v)->{
            Set<RequestMethod> methods = k.getMethodsCondition().getMethods();
            if (CollectionUtils.isEmpty(methods)){
                methods = new HashSet<>();
                methods.add(RequestMethod.GET);
                methods.add(RequestMethod.POST);
            }
            final Set<String> patterns = k.getPatternsCondition().getPatterns();
            for (RequestMethod method : methods) {
                for (String pattern : patterns) {
                    System.err.println("method:"+method+" "+"uri:"+pattern);
                    }
            }
        });
    }

 

 

END。

相关标签: 获取uri