From b16ec9cf246a316220716b43927bcfe2a62e9eca Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 11 Nov 2024 11:34:31 +0000 Subject: [PATCH] Ensure global interceptors are added to Servlet Builds on #42 and #1. --- samples/grpc-tomcat/pom.xml | 8 ++++++++ .../grpc-tomcat/src/main/resources/application.properties | 4 +++- .../server/GrpcServerFactoryAutoConfiguration.java | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/samples/grpc-tomcat/pom.xml b/samples/grpc-tomcat/pom.xml index a6c866e..c50b9ec 100644 --- a/samples/grpc-tomcat/pom.xml +++ b/samples/grpc-tomcat/pom.xml @@ -61,6 +61,14 @@ io.grpc grpc-servlet-jakarta + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-tracing-bridge-otel + org.springframework.boot diff --git a/samples/grpc-tomcat/src/main/resources/application.properties b/samples/grpc-tomcat/src/main/resources/application.properties index 5f753c5..28f590b 100644 --- a/samples/grpc-tomcat/src/main/resources/application.properties +++ b/samples/grpc-tomcat/src/main/resources/application.properties @@ -1,3 +1,5 @@ spring.application.name=grpc-tomcat server.port=9090 -server.http2.enabled=true \ No newline at end of file +server.http2.enabled=true +logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}] +management.endpoints.web.exposure.include=* diff --git a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerFactoryAutoConfiguration.java b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerFactoryAutoConfiguration.java index 280c123..0a4b4a1 100644 --- a/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerFactoryAutoConfiguration.java +++ b/spring-grpc-spring-boot-autoconfigure/src/main/java/org/springframework/grpc/autoconfigure/server/GrpcServerFactoryAutoConfiguration.java @@ -31,9 +31,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; +import org.springframework.grpc.server.GrpcServiceDiscoverer; import org.springframework.util.unit.DataSize; import io.grpc.BindableService; +import io.grpc.ServerServiceDefinition; import io.grpc.servlet.jakarta.GrpcServlet; import io.grpc.servlet.jakarta.ServletServerBuilder; @@ -67,9 +69,10 @@ public class GrpcServerFactoryAutoConfiguration { @Bean public ServletRegistrationBean grpcServlet(GrpcServerProperties properties, - List services, ServerBuilderCustomizers serverBuilderCustomizers) { + GrpcServiceDiscoverer discoverer, ServerBuilderCustomizers serverBuilderCustomizers) { + List services = discoverer.findServices(); List paths = services.stream() - .map(service -> "/" + service.bindService().getServiceDescriptor().getName() + "/*") + .map(service -> "/" + service.getServiceDescriptor().getName() + "/*") .collect(Collectors.toList()); ServletServerBuilder servletServerBuilder = new ServletServerBuilder(); services.forEach(servletServerBuilder::addService);