Skip to content

Commit 33483bb

Browse files
author
Dave Syer
committed
Revert ServerServiceDefinition bean provider
In retrospect I think users should not have to create ServerServiceDefinitions. It doesn't help anybody and it seems like quite a deep internal detail.
1 parent 80e7034 commit 33483bb

File tree

4 files changed

+4
-25
lines changed

4 files changed

+4
-25
lines changed

spring-grpc-docs/src/main/antora/modules/ROOT/pages/server.adoc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ The `Server` is the gRPC server that listens for incoming requests and routes th
77

88
== Create a gRPC Service
99

10-
To create a gRPC server, you need to provide one or more beans of type `BindableService` or `ServerServiceDefinition`.
10+
To create a gRPC server, you need to provide one or more beans of type `BindableService`.
1111
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).
1212
Very commonly, you will create your own `BindableService` by extending the generated service implementation from your Protobuf file.
1313
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.
14-
Alternatively, you could create an instance of it in a `@Configuration` class and return it as a bean, or return it's `ServerServiceDefinition`.
15-
The last option is useful if you need to add specific behaviour, like an interceptor, to the service.
16-
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.
1714

1815
== Netty Server
1916

spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/DefaultGrpcServiceDiscoverer.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,14 @@ class DefaultGrpcServiceDiscoverer implements GrpcServiceDiscoverer {
3636

3737
private final ObjectProvider<BindableService> grpcServicesProvider;
3838

39-
private ObjectProvider<ServerServiceDefinition> grpcServiceDefinitionsProvider;
40-
41-
DefaultGrpcServiceDiscoverer(ObjectProvider<BindableService> grpcServicesProvider,
42-
ObjectProvider<ServerServiceDefinition> grpcServiceDefinitionsProvider) {
39+
DefaultGrpcServiceDiscoverer(ObjectProvider<BindableService> grpcServicesProvider) {
4340
this.grpcServicesProvider = grpcServicesProvider;
44-
this.grpcServiceDefinitionsProvider = grpcServiceDefinitionsProvider;
4541
}
4642

4743
@Override
4844
public List<ServerServiceDefinition> findServices() {
4945
List<ServerServiceDefinition> list = new ArrayList<>(
5046
grpcServicesProvider.orderedStream().map(BindableService::bindService).toList());
51-
list.addAll(grpcServiceDefinitionsProvider.orderedStream().toList());
5247
return list;
5348
}
5449

spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfiguration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import io.grpc.CompressorRegistry;
3737
import io.grpc.DecompressorRegistry;
3838
import io.grpc.ServerBuilder;
39-
import io.grpc.ServerServiceDefinition;
4039

4140
/**
4241
* {@link EnableAutoConfiguration Auto-configuration} for gRPC server-side components.
@@ -76,9 +75,8 @@ ServerBuilderCustomizers serverBuilderCustomizers(ObjectProvider<ServerBuilderCu
7675

7776
@ConditionalOnMissingBean
7877
@Bean
79-
GrpcServiceDiscoverer grpcServiceDiscoverer(ObjectProvider<BindableService> bindableServicesProvider,
80-
ObjectProvider<ServerServiceDefinition> serviceDefinitionsProvider) {
81-
return new DefaultGrpcServiceDiscoverer(bindableServicesProvider, serviceDefinitionsProvider);
78+
GrpcServiceDiscoverer grpcServiceDiscoverer(ObjectProvider<BindableService> bindableServicesProvider) {
79+
return new DefaultGrpcServiceDiscoverer(bindableServicesProvider);
8280
}
8381

8482
@ConditionalOnBean(CompressorRegistry.class)

spring-grpc-spring-boot-autoconfigure/src/test/java/org/springframework/grpc/autoconfigure/server/GrpcServerAutoConfigurationTests.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,6 @@ void grpcServiceDiscovererAutoConfiguredAsExpected() {
134134
.containsExactly(this.serviceDefinition));
135135
}
136136

137-
@Test
138-
void grpcServiceDiscovererWithServiceDefinitionAsExpected() {
139-
ServerServiceDefinition serviceDefinition = ServerServiceDefinition.builder("my-other-service").build();
140-
this.contextRunnerWithLifecyle()
141-
.withBean(ServerServiceDefinition.class, () -> serviceDefinition)
142-
.run((context) -> assertThat(context).getBean(GrpcServiceDiscoverer.class)
143-
.extracting(GrpcServiceDiscoverer::findServices,
144-
InstanceOfAssertFactories.list(ServerServiceDefinition.class))
145-
.containsExactly(this.serviceDefinition, serviceDefinition));
146-
}
147-
148137
@Test
149138
void whenHasUserDefinedServerBuilderCustomizersDoesNotAutoConfigureBean() {
150139
ServerBuilderCustomizers customCustomizers = mock(ServerBuilderCustomizers.class);

0 commit comments

Comments
 (0)