Spring Boot provides extensive integration for gRPC, supporting both client and server components. The integration is built upon the spring-grpc project and includes auto-configuration for observability, health monitoring, security, and externalized configuration.
The gRPC integration is primarily driven by two configuration property classes that map external properties to gRPC components.
GrpcServerProperties module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerProperties.java40 manages the lifecycle and behavior of the gRPC server. Key configuration areas include:
GrpcClientProperties module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientProperties.java41 allows for named channel configurations module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientProperties.java46-50 Each channel can define its own:
static://localhost:9090) module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientProperties.java57-62gRPC Configuration Mapping
| Feature | Server Property | Client Property |
|---|---|---|
| Message Size | spring.grpc.server.inbound.message.max-size | spring.grpc.client.channel.<name>.inbound.message.max-size |
| Keep-alive Time | spring.grpc.server.keepalive.time | spring.grpc.client.channel.<name>.keepalive.time |
| SSL/TLS | spring.grpc.server.ssl.* | spring.grpc.client.channel.<name>.ssl.* |
Sources: module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerProperties.java40-267 module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientProperties.java41-247
Spring Boot auto-configures Micrometer-based observations for both client and server using specialized interceptors.
GrpcServerObservationAutoConfiguration module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerObservationAutoConfiguration.java47-54 registers an ObservationGrpcServerInterceptor module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerObservationAutoConfiguration.java60-65GrpcClientObservationAutoConfiguration module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientObservationAutoConfiguration.java42-49 registers an ObservationGrpcClientInterceptor marked with @GlobalClientInterceptor module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientObservationAutoConfiguration.java52-59gRPC Observation Data Flow
Sources: module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/GrpcServerObservationAutoConfiguration.java47-65 module/spring-boot-grpc-client/src/main/java/org/springframework/boot/grpc/client/autoconfigure/GrpcClientObservationAutoConfiguration.java42-61
The gRPC server health integration bridges Spring Boot's Actuator health indicators with the standard gRPC Health Checking Protocol (io.grpc.health.v1).
Key features include:
Status (e.g., UP, DOWN) to gRPC ServingStatus (e.g., SERVING, NOT_SERVING) via GrpcServerHealthProperties module/spring-boot-grpc-server/src/main/java/org/springframework/boot/grpc/server/autoconfigure/health/GrpcServerHealthProperties.java169-180Spring Boot provides auto-configuration for securing gRPC endpoints using Spring Security.
When running gRPC over a Servlet-based transport, CSRF protection is typically unnecessary as gRPC clients do not use browser-based cookie authentication by default. The spring.grpc.server.security.csrf.enabled property module/spring-boot-grpc-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json29-33 controls this behavior, defaulting to false.
Integration with OAuth2 allows the gRPC server to validate JWT or Opaque tokens, securing services using standard Authorization: Bearer <token> metadata.
Security Entity Mapping
The ProtobufPluginAction build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java46 reacts to the application of the Google Protobuf Gradle plugin.
protoc and the grpc plugin with the versions found on the project's runtime classpath build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java52-54protoc artifact to com.google.protobuf:protoc build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java71-73 and the grpc plugin to io.grpc:protoc-gen-grpc-java build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java76-79GenerateProtoTask to include the @generated=omit option for gRPC build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java90-92Build Logic Flow
Sources: build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ProtobufPluginAction.java46-158 build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/reacting.adoc110-119
The repository uses smoke tests to validate gRPC functionality. These tests use the PluginClasspathGradleBuild build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java57 to ensure the gRPC and Protobuf plugins are correctly available in the test environment build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java129-132
Verification includes checking that the protoc artifact and grpc plugin options are correctly applied during the build process build-plugin/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/ProtobufPluginActionIntegrationTests.gradle42-68
Sources: build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java129-132 build-plugin/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/ProtobufPluginActionIntegrationTests.gradle42-68