Spring boot执行器映射:添加端点描述| Spring Boot3.3.0-堆栈溢出 最近30次来自stackoverflow.com 2024-07-02T19:57:45 Z https://stackoverflow.com/feeds/question/78634409 https://creativecommons.org/licenses/by-sa/4.0/rdf https://stackoverflow.com/q/78634409 0 Spring boot执行器映射:添加端点描述|Spring Boot3.3.0 尼克·M。 https://stackoverflow.com/users/23713762 2024-06-17T19:41:06Z 2024-06-19T08:14:03分 <p>我在我的spring-boot项目中使用了spring-doc-open-api。在我的rest控制器中,我有两个端点,它们相同,只是参数和requestbody的内容不同。示例:</p><pre class=“lang-java prettyprint-override”><code>@PostMapping(value=&quot;/v1/types;,params=&quort;type=typeA)...@PostMapping(值=/v1/types,参数=typeB)</code></pre><p>由于OpenAPI规范,端点应该是唯一的,并且参数不被视为路径的一部分。所以招摇的ui只显示了一个端点,我猜是按字母顺序排列的第一个端点</p>(第页)<p>在我的情况下,我的前端团队需要知道在我的api中使用哪些端点。因此,我从执行器/映射端点中找到了另一种选择,它显示了我项目中的每个端点,实际上是我所需要的</p>(第页)<p>我的问题是,我需要为每个端点添加一些描述,以描述哪些对象是必需的,以及端点到底做了什么</p>(第页)<p>有没有办法在/actuator/mappings中列出的端点下添加某种描述</p>(第页)<p>仅供参考:Spring Boot 3.3.0</p><p>Swagger API迭代了很多,比如向端点添加一些信息,比如@Operation、@APIResponses或@Parameter注释,但用不同的参数显示同一个端点没有帮助</p>(第页)<p>我查看了官方的弹簧启动执行器文档,但没有相关信息</p> https://stackoverflow.com/questions/78634409/spring-boot-actuator-mapping-add-description-of-endpoints-spring-boot-3-3-0/78635575#78635575 0 Abhishek Kotalwar关于Spring boot执行器映射的回答:添加端点描述|Spring Boot3.3.0 阿披实科塔尔瓦尔 https://stackoverflow.com/users/7012221 2024-06-18T05:13:03分 2024-06-19T08:14:03分 <p>您可以像下面这样使用弹簧防尘套执行器</p><p><strong>在pom.xml中添加依赖项:</p><pre><code>&lt;依赖性&gt;&它;组Id&gt;org.springframework.boot&lt/组Id&gt;&它;artifactId&gt;弹簧启动执行器&lt/artifactId&gt;&它/依赖性&gt;</code></pre><p><strong>创建自定义端点</p><pre><code>@组件@端点(id=自定义映射)公共类CustomMappingsEndpoint{私有最终ApplicationContext ApplicationContext;@自动连线公共CustomMappingsEndpoint(ApplicationContext ApplicationContext){this.applicationContext=应用程序上下文;}@读取操作公共地图&lt;字符串,对象&gt;自定义映射(){映射&lt;字符串,对象&gt;mappings=新HashMap&lt&gt;();映射&lt;字符串,RequestMappingHandlerMapping&gt;allRequestMappings=应用程序上下文.getBeansOfType(RequestMappingHandlerMapping.class);for(RequestMappingHandlerMapping handlerMaping:allRequestMapbings.values()){映射&lt;RequestMappingInfo、HandlerMethod&gt;handlerMethods=handlerMapping.getHandlerMethods();对于(Map.Entry&lt;RequestMappingInfo,HandlerMethod&gt;Entry:handlerMethods.entrySet()){RequestMappingInfo requestMappingInform=条目.getKey();HandlerMethod handlerMeth=条目.getValue();//从PathPatternsRequestCondition提取路径PathPatternsRequestCondition路径PatternsCondition=requestMappingInfo.getPathPatentersCondition();设置&lt;字符串&gt;patterns=路径PatternsCondition!=无效的?pathPatternsCondition.getPatternValues():空;if(patterns!=null&amp;&amp!patterns.isEmpty()){if(isExcludedPath(patterns.iterator().next())){继续;//跳过此路径}}映射&lt;字符串,对象&gt;endpointInfo=new HashMap&lt&gt;();endpointInfo.put(路径,模式.iterator().next());endpointInfo.put(方法;,requestMappingInfo.getMethodsCondition()!=无效的? 请求映射信息.获取方法条件().获取方法():&quot;未知(&quot;);endpointInfo.put(参数;,requestMappingInfo.getParamsCondition()!=无效的? requestMappingInfo.getParamsCondition().getExpressions():&quot;未知(&quot;);endpointInfo.put(描述,handlerMethod.getMethod().getName());mappings.put(handlerMethod.getMethod().getName(),endpointInfo);}}返回映射;}private boolean isExcludedPath(字符串路径){//定义要排除的路径return path.startsWith(“/v3/api docs”)|| path.startsWith(“/error”)|| path.startsWith(“/swagger ui.html”)||path.startsWith(/v3/api-docs.yaml&quot;);//根据需要添加更多路径}</code></pre><p><strong>在应用程序中公开自定义端点。属性</p><pre><code>management.endpoints.web.exposure.include=自定义映射</code></pre><p>使用以下URL获取有关端点的信息</p><预><代码>http://server:port/context-路径/执行器/自定义映射</code></pre><p><strong>输出:</strong></p><pre><code>{方法1&quot;:{路径:/v1/types,方法:[&quot;:false}]},&quot;方法2:{路径:/v1/types&quot;,方法:[&quot;方法3:{路径:/v1/getTypes,方法:[GET&quot;],描述:method3[quot;,参数:[]}}</code></pre>