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内部处理流程分析
下一篇: HCIA第二天