解决Spring Boot 2.6以上 与Swagger 3.0.0 不兼容问题

本文介绍了在SpringBoot2.6及以上版本中解决与Swagger3.0.0不兼容问题的方法,主要涉及`WebMvcEndpointHandlerMapping`的配置,以及如何处理`ExposableEndpoint`和`EndpointMapping`的设置。
摘要由CSDN通过智能技术生成
  1. /**
  2. * 增加如下配置可解决Spring Boot 2.6以上 与Swagger 3.0.0 不兼容问题
  3. **/
  4. @Bean
  5. public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping
  6. (WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
  7. ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
  8. List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
  9. Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
  10. allEndpoints.addAll(webEndpoints);
  11. allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
  12. allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
  13. String basePath = webEndpointProperties.getBasePath();
  14. EndpointMapping endpointMapping = new EndpointMapping(basePath);
  15. boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
  16. return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
  17. }
  18. private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
  19. return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
  20. }
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值