- /**
- * 增加如下配置可解决Spring Boot 2.6以上 与Swagger 3.0.0 不兼容问题
- **/
- @Bean
- public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping
- (WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
- ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
- List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
- Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
- allEndpoints.addAll(webEndpoints);
- allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
- allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
- String basePath = webEndpointProperties.getBasePath();
- EndpointMapping endpointMapping = new EndpointMapping(basePath);
- boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
- return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
- }
- private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
- return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
- }
解决Spring Boot 2.6以上 与Swagger 3.0.0 不兼容问题
最新推荐文章于 2024-07-27 18:17:36 发布
本文介绍了在SpringBoot2.6及以上版本中解决与Swagger3.0.0不兼容问题的方法,主要涉及`WebMvcEndpointHandlerMapping`的配置,以及如何处理`ExposableEndpoint`和`EndpointMapping`的设置。
摘要由CSDN通过智能技术生成