diff --git a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc index b502e21..e33bb1d 100644 --- a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc +++ b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc @@ -7,13 +7,10 @@ The `Server` is the gRPC server that listens for incoming requests and routes th == Create a gRPC Service -To create a gRPC server, you need to provide one or more beans of type `BindableService` or `ServerServiceDefinition`. +To create a gRPC server, you need to provide one or more beans of type `BindableService`. There are some `BindableServices` available off the shelf that you could include in your application (an example is the reflection service from the `grpc-services` artifact which allows clients to browse the metadata of your services and download the Portobuf files). Very commonly, you will create your own `BindableService` by extending the generated service implementation from your Protobuf file. The easiest way to activate it is to simply add a Spring `@Service` annotation to the implementation class and have it picked up by the `@ComponentScan` in your Spring Boot application. -Alternatively, you could create an instance of it in a `@Configuration` class and return it as a bean, or return it's `ServerServiceDefinition`. -The last option is useful if you need to add specific behaviour, like an interceptor, to the service. -It is an error to have more than one instance of the same service name, so don't create both a `BindableService` and a `ServerServiceDefinition` bean for the same service. == Netty Server diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/DefaultGrpcServiceDiscoverer.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/DefaultGrpcServiceDiscoverer.java index c39d8ed..35c3f36 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/DefaultGrpcServiceDiscoverer.java +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/DefaultGrpcServiceDiscoverer.java @@ -36,19 +36,14 @@ class DefaultGrpcServiceDiscoverer implements GrpcServiceDiscoverer { private final ObjectProvider grpcServicesProvider; - private ObjectProvider grpcServiceDefinitionsProvider; - - DefaultGrpcServiceDiscoverer(ObjectProvider grpcServicesProvider, - ObjectProvider grpcServiceDefinitionsProvider) { + DefaultGrpcServiceDiscoverer(ObjectProvider grpcServicesProvider) { this.grpcServicesProvider = grpcServicesProvider; - this.grpcServiceDefinitionsProvider = grpcServiceDefinitionsProvider; } @Override public List findServices() { List list = new ArrayList<>( grpcServicesProvider.orderedStream().map(BindableService::bindService).toList()); - list.addAll(grpcServiceDefinitionsProvider.orderedStream().toList()); return list; } diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java index 2255c50..53cff8d 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java @@ -36,7 +36,6 @@ import io.grpc.BindableService; import io.grpc.CompressorRegistry; import io.grpc.DecompressorRegistry; import io.grpc.ServerBuilder; -import io.grpc.ServerServiceDefinition; /** * {@link EnableAutoConfiguration Auto-configuration} for gRPC server-side components. @@ -76,9 +75,8 @@ public class GrpcServerAutoConfiguration { @ConditionalOnMissingBean @Bean - GrpcServiceDiscoverer grpcServiceDiscoverer(ObjectProvider bindableServicesProvider, - ObjectProvider serviceDefinitionsProvider) { - return new DefaultGrpcServiceDiscoverer(bindableServicesProvider, serviceDefinitionsProvider); + GrpcServiceDiscoverer grpcServiceDiscoverer(ObjectProvider bindableServicesProvider) { + return new DefaultGrpcServiceDiscoverer(bindableServicesProvider); } @ConditionalOnBean(CompressorRegistry.class) diff --git a/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfigurationTests.java b/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfigurationTests.java index 2f99afb..300c340 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfigurationTests.java +++ b/spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfigurationTests.java @@ -134,17 +134,6 @@ class GrpcServerAutoConfigurationTests { .containsExactly(this.serviceDefinition)); } - @Test - void grpcServiceDiscovererWithServiceDefinitionAsExpected() { - ServerServiceDefinition serviceDefinition = ServerServiceDefinition.builder("my-other-service").build(); - this.contextRunnerWithLifecyle() - .withBean(ServerServiceDefinition.class, () -> serviceDefinition) - .run((context) -> assertThat(context).getBean(GrpcServiceDiscoverer.class) - .extracting(GrpcServiceDiscoverer::findServices, - InstanceOfAssertFactories.list(ServerServiceDefinition.class)) - .containsExactly(this.serviceDefinition, serviceDefinition)); - } - @Test void whenHasUserDefinedServerBuilderCustomizersDoesNotAutoConfigureBean() { ServerBuilderCustomizers customCustomizers = mock(ServerBuilderCustomizers.class);