@GrpcService marks a class that implements a generated gRPC service base class as a Spring bean and registers it with the embedded gRPC server automatically. It comes from the community library grpc-spring-boot-starter (package net.devh.boot.grpc.server.service), not from Spring itself. The official Spring gRPC project takes a different approach: it registers any BindableService bean, so no special annotation is needed.
Either way, the idea is the same: you write the service logic, and the starter starts the server, adds your service to it and ties its lifecycle to the application.
@GrpcService is meta-annotated with @Service, so Spring creates the class as a bean. The starter then collects every bean with this annotation, wraps it as a gRPC ServerServiceDefinition and adds it to the Server it builds at startup.
Without a starter you would write this by hand:
With the starter you annotate the class and the server, port, shutdown handling and interceptors are configured for you. The annotation also accepts attributes such as interceptors and interceptorNames to attach service-specific interceptors.
gRPC services start from a Protocol Buffers file. The build plugin generates the Java message classes and the GreeterGrpc base class.
Put the file in src/main/proto/. Use protobuf-maven-plugin or the com.google.protobuf Gradle plugin together with the gRPC Java plugin to generate the code during the build. Generated sources should not be committed.
Add the server starter. With Maven the dependency is:
Check the project's release page for the version that matches your Spring Boot line, since this is a community library and compatibility with new Spring Boot major versions can lag. Then implement the service:
A unary RPC sends exactly one response with onNext and then calls onCompleted. To report a failure, call responseObserver.onError(Status.NOT_FOUND.withDescription("...").asRuntimeException()).
The starter reads properties with the grpc.server prefix:
The default port is 9090, and 0 picks a random free port, which is handy in tests. Enabling the reflection service lets tools such as grpcurl list and call services without the .proto file. This is useful in development; think twice before exposing it in production.
You can test the running service with grpcurl:
Use interceptors for authentication, logging and metrics. Annotate an interceptor bean with @GrpcGlobalServerInterceptor to apply it to every service, or reference interceptors from @GrpcService(interceptors = ...) for one service. Exceptions can be translated to gRPC status codes with a @GrpcAdvice class and @GrpcExceptionHandler methods, so service code can throw domain exceptions.
Spring now has its own gRPC project, Spring gRPC, with a Boot starter. It auto-registers any bean that implements BindableService, so a plain @Service on the implementation class is enough and @GrpcService is not used. Its properties live under the spring.grpc prefix. For a new application, evaluate it first, because it follows the Spring release cycle. Keep @GrpcService for projects already on the community starter.
| Aspect | net.devh starter | Spring gRPC |
|---|---|---|
| Maintainer | Community project | Spring team |
| Registration | @GrpcService | Any BindableService bean |
| Property prefix | grpc.server | spring.grpc.server |
| Spring Boot support | Check release notes per version | Follows Spring Boot releases |
No. It belongs to the community grpc-spring-boot-starter. Spring gRPC is the official alternative and does not use that annotation.
The community starter defaults to 9090. Set grpc.server.port to change it.
Yes. gRPC runs on its own port next to the web server, so one application can expose both.
Use an in-process server with grpc-testing or spring-boot-test with a random port, and call it through a generated stub.
@GrpcService turns your implementation of a generated gRPC base class into a Spring-managed service that the starter registers with the gRPC server automatically. It is a feature of the community net.devh starter; Spring gRPC achieves the same by registering BindableService beans. Define the contract in a .proto file, generate the stubs at build time and implement them as thin classes.