Skip to content

Add autoconfiguration for gRPC servlet #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2024
Merged

Conversation

dsyer
Copy link
Member

@dsyer dsyer commented Oct 23, 2024

In a web application, if there are BindableServices we use
a servlet instead of a netty-based server.

Fixes #18

@dsyer dsyer requested a review from onobc October 23, 2024 10:19
@dsyer dsyer force-pushed the tomcat branch 3 times, most recently from 4cab4b2 to 25b384b Compare October 23, 2024 10:25
Dave Syer added 2 commits October 23, 2024 11:26
Signed-off-by: Dave Syer <dsyer@vmware.com>
Signed-off-by: Dave Syer <dsyer@vmware.com>
Copy link
Contributor

@onobc onobc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool stuff @dsyer . I have added a few comments/concerns.


@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication
static class GrpcServletConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are limited options for the ServletServerBuilder so providing a custom server factory is overkill since the ServletAdapter#init does the same thing we would be doing:

  public GrpcServlet(List<? extends BindableService> bindableServices) {
    this(loadServices(bindableServices));
  }

  private static ServletAdapter loadServices(List<? extends BindableService> bindableServices) {
    ServletServerBuilder serverBuilder = new ServletServerBuilder();
    bindableServices.forEach(serverBuilder::addService);
    return serverBuilder.buildServletAdapter();
  }

@dsyer dsyer force-pushed the tomcat branch 2 times, most recently from ab2f005 to 401188e Compare October 24, 2024 07:37
Signed-off-by: Dave Syer <dsyer@vmware.com>
@dsyer dsyer merged commit b5a6232 into spring-projects:main Oct 25, 2024
2 checks passed
@dsyer dsyer deleted the tomcat branch October 25, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support using the same port for Spring MVC and gRPC
2 participants