Gateway forwards weboskct with an error ClassCastException

    usage environment: the springcloud gateway forwards an error message to the websocket. Error message content:

    15:30:38.092 [http-nio-9999-exec-1] ERROR c.m.g.e.GlobalErrorWebExceptionHandler - [handle,38] - org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponse
    java.lang.ClassCastException: org.apache.catalina.connector.ResponseFacade cannot be cast to reactor.netty.http.server.HttpServerResponse
    	at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.getNativeResponse(ReactorNettyRequestUpgradeStrategy.java:182)
    	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
    Error has been observed at the following site(s):
    	|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    	|_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
    	|_ checkpoint ⇢ HTTP GET "/sys/websocket/1" [ExceptionHandlingWebHandler]
    Stack trace:
    		at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.getNativeResponse(ReactorNettyRequestUpgradeStrategy.java:182)
    		at org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy.upgrade(ReactorNettyRequestUpgradeStrategy.java:162)
    		at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.lambda$handleRequest$1(HandshakeWebSocketService.java:235)
    		at reactor.core.publisher.FluxFlatMap.trySubscribeScalarMap(FluxFlatMap.java:151)
    		at reactor.core.publisher.MonoFlatMap.subscribeOrReturn(MonoFlatMap.java:53)
    		at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:57)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.Mono.subscribe(Mono.java:4252)
    		at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172)
    		at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
    		at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at com.alibaba.csp.sentinel.adapter.reactor.MonoSentinelOperator.subscribe(MonoSentinelOperator.java:40)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    		at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
    		at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
    
      cause of error: dependency conflict
      the Tomcat servlet of springboot is used in the request and the Tomcat of gateway netty is used in the response, so the type conversion exception is caused. Solution: modify the gateway POM file:
      delete or exclude the following dependencies

      <dependency>
      	<groupId>javax.servlet</groupId>
      	<artifactId>javax.servlet-api</artifactId>
      </dependency>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
       <dependency>
      	<groupId>javax.servlet</groupId>
      	<artifactId>jstl</artifactId>
      </dependency>
      <dependency>
      	<groupId>org.apache.tomcat.embed</groupId>
      	<artifactId>tomcat-embed-jasper</artifactId>
      </dependency>
      

Read More: