Spring Cloud Gateway 依赖冲突问题

今天在配置运行Spring Cloud Gateway的时候出现了这个错误

在这里插入图片描述

Description:

Parameter 0 of method websocketRoutingFilter in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.web.reactive.socket.client.WebSocketClient' that could not be found.

The following candidates were found but could not be injected:
	- Bean method 'reactorNettyWebSocketClient' in 'GatewayAutoConfiguration.NettyConfiguration' not loaded because @ConditionalOnClass did not find required class 'reactor.ipc.netty.http.client.HttpClient'


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.web.reactive.socket.client.WebSocketClient' in your configuration.

这是maven所使用到的依赖

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/>
	</parent>
    
    <modelVersion>4.0.0</modelVersion>
    <artifactId>gateway</artifactId>
    <name>gateway</name>
    <description>Spring 
### 解决Spring Cloud GatewaySpringDoc的冲突问题 当遇到Spring Cloud GatewaySpringDoc之间存在兼容性问题时,通常是因为两者对于API文档路径处理机制的不同所引起的。具体来说,在某些情况下,默认配置可能会导致请求被错误路由或拦截。 一种常见的解决方案是在应用中自定义`WebMvcEndpointHandlerMapping` Bean来调整端点映射逻辑[^3]。通过这种方式可以改变原有的路径匹配模式,从而避免潜在的冲突。下面是一个具体的实现方法: #### 自定义WebMvcEndpointHandlerMapping Bean 创建一个新的Java类用于重新定义`WebMvcEndpointHandlerMapping` Bean,确保其采用不同的路径匹配器(例如AntPathMatcher),而不是默认的方式。这可以通过继承原有类并重写相应的方法来完成。 ```java import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; import org.springframework.boot.actuate.endpoint.annotation.ControllerEndpointsSupplier; import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CustomWebMvcEndpointHandlerMapping { @Bean public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping( ObjectProvider<List<ExposableControllerEndpoint>> endpointProviders, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsConfiguration corsConfiguration, WebEndpointProperties webEndpointProperties) { List<ExposableControllerEndpoint> endpoints = new ArrayList<>(); endpointProviders.ifAvailable(endpoints::addAll); return new WebMvcEndpointHandlerMapping(webEndpointProperties.getBasePath(), endpoints, controllerEndpointsSupplier, endpointMediaTypes, corsConfiguration, new AntPathMatcher()); } } ``` 上述代码片段展示了如何通过注入必要的依赖项来自定义`WebMvcEndpointHandlerMapping`实例,并指定使用`AntPathMatcher`来进行路径匹配操作。 此外,如果正在使用的SpringCloud版本较新,则可能还需要考虑集成最新版的springdoc-openapi库以获得更好的支持[^2]。确保项目中的依赖关系是最新的可以帮助减少因不同模块间不一致而引发的问题。 最后,针对特定场景下的特殊需求,还可以进一步探索其他可选方案,比如调整gateway的过滤链设置或是修改openapi生成的相关参数等措施。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值