How to use SpringBoot to get routes for all interfaces
This article focuses on "how to use SpringBoot to get the routing of all interfaces", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use SpringBoot to get routes for all interfaces".
Catalogue
SpringBoot acquires routes for all interfaces
Springboot partial routing takes effect
Problem record
SpringBoot gets the route @ Autowired WebApplicationContext applicationContext; @ RequestMapping of all interfaces (value = "v1/getAllUrl", method = RequestMethod.POST) public Object getAllUrl () {RequestMappingHandlerMapping mapping = applicationContext.getBean (RequestMappingHandlerMapping.class); / / gets the corresponding information of url and class and method Map map = mapping.getHandlerMethods (); / / List urlList = new ArrayList () / / for (RequestMappingInfo info: map.keySet ()) {/ get the Set collection of url. A method may correspond to multiple url// Set patterns = info.getPatternsCondition () .getPatterns (); / for (String url: patterns) {/ / urlList.add (url); / /} / /} List list = new ArrayList () For (Entry m: map.entrySet ()) {Map map1 = new HashMap (); RequestMappingInfo info = m.getKey (); HandlerMethod method = m.getValue (); PatternsRequestCondition p = info.getPatternsCondition (); for (String url: p.getPatterns ()) {map1.put ("url", url) } map1.put ("className", method.getMethod (). GetDeclaringClass (). GetName ()); / / Class name map1.put ("method", method.getMethod (). GetName ()); / / method name RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition () For (RequestMethod requestMethod: methodsCondition.getMethods ()) {map1.put ("type", requestMethod.toString ());} list.add (map1);} Springboot partial routing problem record
The new interface "foo" of the project never takes effect. After investigation, it is found that the basic path "test" is added to @ RequestMaping (value= "test") of the controller layer, and my new interface is annotated as @ PostMappinp ("test/foo). As a result, the generated route is" test/test/foo "and the call address is" test/foo ".
At this point, I believe you have a deeper understanding of "how to use SpringBoot to get the routing of all interfaces". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!