I need to capture all the URLs when I do permission control, which will be because of the need to request type, filter some URLs without request type, without saying much, code.
Configuration @Slf4j public class RolePolicyConfig { private final WebApplicationContext context; @Autowired public RolePolicyConfig(WebApplicationContext context) { this.context = context; } @ PostConstruct public void methodInit () {/ / get RequestMappingHandlerMapping mapping = context.getBean(RequestMappingHandlerMapping.class); / / url with classes and methods corresponding information Map < RequestMappingInfo, HandlerMethod > Map = mapping. GetHandlerMethods (); // ArrayList< Map<String, String bb0 > ListMap = new ArrayList<>(); for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) { Map<String, String> initMap = new HashMap<>(); RequestMappingInfo info = entry.getKey(); / / request type RequestMethodsRequestCondition methodsCondition = info. GetMethodsCondition (); / / request url PatternsRequestCondition pattern = info. GetPatternsCondition (); / / if the type is not null, to obtain the Set < RequestMethod >. The methods = methodsCondition getMethods (); if (! ObjectUtils.isEmpty(pattern) && ! CollectionUtils.isEmpty(methods)) { if (! CollectionUtils.isEmpty(Patch.getPatterns ()))) {log.info(" Method Name: {}", Entry.getValue ().getMethod().getName())); Set<String> patterns = pattern.getPatterns(); Log.info (" get url: {}", pattern.toString ()); for (String url : patterns) { initMap.put("url", url); initMap.put("name", url.replaceAll("/", "_").substring(1)); } for (RequestMethod requestMethod : methods) { initMap.put("type", requestMethod.toString()); } } listMap.add(initMap); }} log.info(" Get all url: {}", json.tojsonstring (listMap)); }}