-
Notifications
You must be signed in to change notification settings - Fork 87
Spring gRPC Migration from Ecosystem Projects
-
Replace
net.devh:grpc-client-spring-boot-starterwithorg.springframework.boot:spring-boot-starter-grpc-server(for server apps) and/ororg.springframework.boot:spring-boot-starter-grpc-client(for client apps) in your Gradle or Maven build. Replaceorg.springframework.grpc:spring-grpc-testwithorg.springframework.boot:spring-boot-starter-grpc-client-test. You no longer need to import a separate BOM — dependency versions are managed by Spring Boot 4.1.0 itself. -
Classes annotated
@GrpcGlobalServerInterceptorshould now be annotated@Componentand@GlobalServerInterceptorinstead. (Search and replace imports and annotations.) Classes annotated@GrpcGlobalClientInterceptorshould now be annotated@Componentand@GlobalClientInterceptorinstead. (Search and replace imports and annotations.) Search and replacenet.devh.boot.grpc.server.service.GrpcServicewithorg.springframework.grpc.server.service.GrpcService. -
Classes annotated
@GrpcAdvicewith methods annotated@GrpcExceptionHandlershould now be annotated@Componentand implement theGrpcExceptionHandlerinterface instead. -
Search and replace
net.devh.boot.grpc.server.security.interceptors.AuthenticatingServerInterceptor.SECURITY_CONTEXT_KEYwithorg.springframework.grpc.server.security.GrpcSecurity.SECURITY_CONTEXT_KEY. -
You may need to implement an
AuthenticationProcessInterceptorand annotate it with@GlobalServerInterceptor. See Declarative Security with Spring Security. -
If you implement
GrpcAuthenticationReader, you'll need to implementGrpcAuthenticationExtractorinstead. -
Replace
@GrpcClientfield injection with@Autowired. In net.devh you annotated stub fields directly:@GrpcClient("myservice") private MyServiceGrpc.MyServiceBlockingStub stub;
In Spring gRPC, declare
@ImportGrpcClientson your application class (or a@Configuration) and autowire normally:@SpringBootApplication @ImportGrpcClients(basePackageClasses = MyServiceGrpc.class) public class MyApplication { ... }
@Autowired private MyServiceGrpc.MyServiceBlockingStub stub;
-
Replace
@GrpcChannelConfigurerbeans withGrpcChannelBuilderCustomizerbeans. To target a specific channel by name, useGrpcChannelBuilderCustomizer.matching("channelName", builder -> ...). -
For SSL/TLS client channels, replace net.devh's
grpc.client.<name>.security.*properties withspring.grpc.client.channel.<name>.ssl.*. Specifically,negotiation-type=TLScombined withsecure=false(meaning skip certificate validation) becomesssl.enabled=trueandbypass-certificate-validation=true. To use an SSL bundle, setssl.bundle=<bundle-name>. -
In tests that use an in-process server, annotate the test class with
@AutoConfigureTestGrpcTransport(previously@AutoConfigureInProcessTransport). Autowire your stubs directly rather than using the@GrpcClient("inProcess")annotation or thegrpc.server.inProcessNameandgrpc.client.inProcess.addressproperties. If your stubs are not already declared as beans, add a@TestConfigurationclass that declares them (using an autowiredGrpcChannelFactoryif needed). Also add@ImportGrpcClients(on the test class or the@TestConfiguration) to register gRPC stubs as Spring beans — this is now required explicitly. -
In your application properties, replace
grpc.server.portwithspring.grpc.server.port,grpc.server.hostwithspring.grpc.server.address, andgrpc.client.<name>.addresswithspring.grpc.client.channel.<name>.target.