Describe the bug
Currently grpc-netty is marked as optional dependency of Spring Cloud Gateway server. jsonToGRPCFilterFactory and gRPCSSLContext beans from the looks of it are also only used for functionality which is not really mandatory.
The problem is that if grpc-api dependency is added to the Spring Cloud Gateway server project (though some external requirement), those GRPC beans get activated which then causes java.lang.NoClassDefFoundError: io/grpc/netty/NettyChannelBuilder.
That's because
|
@ConditionalOnClass(name = "io.grpc.Channel") |
and
|
@ConditionalOnClass(name = "io.grpc.Channel") |
relies on
io.grpc.Channel which is included in
grpc-api.
This produces all sorts of issues when gateway is used with 3rd party dependencies. For example: #2769
The only workaround in such case is to include full grpc-netty dependency even if it is never really used by the gateway.
IMHO, much better solution would be for these beans to rely on io.grpc.netty.GrpcSslContexts or io.grpc.netty.NettyChannelBuilder which is actually used in GrpcSslConfigurer.
Sample
Create standard Spring Cloud Gateway server project and add:
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
Describe the bug
Currently
grpc-nettyis marked as optional dependency of Spring Cloud Gateway server. jsonToGRPCFilterFactory and gRPCSSLContext beans from the looks of it are also only used for functionality which is not really mandatory.The problem is that if
grpc-apidependency is added to the Spring Cloud Gateway server project (though some external requirement), those GRPC beans get activated which then causesjava.lang.NoClassDefFoundError: io/grpc/netty/NettyChannelBuilder.That's because
spring-cloud-gateway/spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java
Line 372 in dd5da25
spring-cloud-gateway/spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java
Line 381 in dd5da25
io.grpc.Channelwhich is included ingrpc-api.This produces all sorts of issues when gateway is used with 3rd party dependencies. For example: #2769
The only workaround in such case is to include full
grpc-nettydependency even if it is never really used by the gateway.IMHO, much better solution would be for these beans to rely on
io.grpc.netty.GrpcSslContextsorio.grpc.netty.NettyChannelBuilderwhich is actually used in GrpcSslConfigurer.Sample
Create standard Spring Cloud Gateway server project and add: