@PostMapping(value=“/v1/types”,params=“type=typeA) ... @PostMapping(value=“/v1/types”,params=“type=typeB)
1答案
<依赖性> <groupId>org.springframework.boot</groupId> <artifactId>弹簧启动执行器 </依赖性>
@组件 @端点(id=“custommappings”) 公共类CustomMappingsEndpoint{ 私有最终ApplicationContext ApplicationContext; @自动连线 公共CustomMappingsEndpoint(ApplicationContext ApplicationContext){ this.applicationContext=应用程序上下文; } @读取操作 公共映射<String,Object>customMappings(){ Map<String,Object>mappings=new HashMap<>(); 映射<String,RequestMappingHandlerMapping>allRequestMapbings=applicationContext .getBeansOfType(RequestMappingHandlerMapping.class); for(RequestMappingHandlerMapping handlerMaping:allRequestMapbings.values()){ 映射<RequestMappingInfo,HandlerMethod>handlerMethods=handlerMapping.getHandlerMethods(); for(Map.Entry<RequestMappingInfo,HandlerMethod>Entry:handlerMethads.entrySet()){ RequestMappingInfo requestMappingInform=条目.getKey(); HandlerMethod handlerMeth=条目.getValue(); //从PathPatternsRequestCondition提取路径 PathPatternsRequestCondition路径PatternsCondition=requestMappingInfo.getPathPatentersCondition(); 设置<String>patterns=pathPatternsCondition!= 无效的? pathPatternsCondition.getPatternValues():空; if(patterns!=null&&!patterns.isEmpty()){ if(isExcludedPath(patterns.iterator().next())){ 继续;// 跳过此路径 } } Map<String,Object>endpointInfo=new HashMap<>(); endpointInfo.put(“路径”,patterns.iterator().next()); endpointInfo.put(“方法”, requestMappingInfo.getMethodsCondition()!= 无效的 ? 请求映射信息.获取方法条件().获取方法() :“未知”); endpointInfo.put(“params”, requestMappingInfo.getParamsCondition()!= 无效的 ? requestMappingInfo.getParamsCondition().getExpressions() :“未知”); endpointInfo.put(“描述”,handlerMethod.getMethod().getName()); mappings.put(handlerMethod.getMethod().getName(),endpointInfo); } } 返回映射; } private boolean isExcludedPath(字符串路径){ //定义要排除的路径 return path.startsWith(“/v3/api-docs”) ||path.startsWith(“/v3/api docs.yaml”); //根据需要添加更多路径 }
management.endpoints.web.exposion.include=自定义映射
http://server:port/context -路径/执行器/自定义映射
{“method1”:{“path”:“/v1/types”,“methods”:[“POST”],“description”:“method1”,“params”:[{“name”:“type”,“value”:“typeA”,“negated”:false}]},“method2”:{“path”:“/v1/types”,“methods”:[“POST”],“description”:“method2”,“params”:[{“name”:“type”,“value”:“typeB”,“negated”:false}]},“method3”:{“path”“:”/v1/getTypes“,”methods“:[”GET“],”description“:”method3“,”params“ :[]}}