gRPC on Tomcat server.

2,101 views
Skip to first unread message

Linesh Mohan

unread,
Nov 27, 2017, 4:24:27 AM11/27/17
to grpc.io
Hello Team,

I am trying to start to gRPC server within a tomcat deployment and facing some issues. I am trying the achieve the following -
I have an app server deployed on tomcat and now I want to use gRPC, hence I want to deploy a gRPC server on the same app server.

Kindly help me with the above case.

Thanks in advance.
Linesh

spenc...@google.com

unread,
Nov 28, 2017, 8:05:57 PM11/28/17
to grpc.io
Hi Linesh,
gRPC expects full control over the listening socket in the case of server side, and expects full control over creating and tearing down connections in the case of client side. This doesn't really fit into the model of a servlet container, which is what Tomcat is. If you really must create a gRPC server on the same JVM as Tomcat, you can add the normal gRPC startup code to whatever server start up code you already have:

Keep in mind that gRPC is not a servlet container, so it will not be able to run your existing Tomcat servlets.

Sheng Zhou

unread,
Apr 30, 2025, 5:32:37 PMApr 30
to grpc.io
It seems to me that it is possible to run gRPC server on Servlet Server sharing the same port, say 8080 (see Servlet Server section of Spring gRPC doc https://docs.spring.io/spring-grpc/reference/server.html). Below is part of my pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath />  <!--lookup parent from repository -->
</parent>

<properties>
<java.version>17</java.version>
<grpc.version>1.70.0</grpc.version>
<protobuf-java.version>3.25.6</protobuf-java.version>
<spring-grpc.version>0.7.0</spring-grpc.version>
</properties>

<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-server-web-spring-boot-starter</artifactId>
</dependency>
... ... ...

Following is the console log when the app starts

toConfiguration$GrpcServletConfiguration : Registering gRPC service: StatusQuery
toConfiguration$GrpcServletConfiguration : Registering gRPC service: grpc.reflection.v1.ServerReflection
toConfiguration$GrpcServletConfiguration : Registering gRPC service: grpc.health.v1.Health

... ... ...

o.s.b.d.a.OptionalLiveReloadServer             : LiveReload server is running on port 35729
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/web-context'
                                          : Started QueryServiceApplication in 23.59 seconds (process running for 25.383)
o.a.c.c.C.[.[.[/web-context]                           : Initializing Spring DispatcherServlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet                       : Initializing Servlet 'dispatcherServlet'
o.s.web.servlet.DispatcherServlet                        : Completed initialization in 3 ms

Then try to call grpc service by using grpcurl but get error

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 HelloWorld.SayHello
Error invoking method "HelloWorld.SayHello": failed to query for service descriptor "HelloWorld": server does not support the reflection API

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 HelloWorld/SayHello
Error invoking method "HelloWorld/SayHello": failed to query for service descriptor "HelloWorld": server does not support the reflection API

grpcurl -d "{\"name\":\"USA\"}" -plaintext localhost:8080 web-context/HelloWorld/SayHello
Error invoking method "web-context/HelloWorld/SayHello": failed to query for service descriptor "web-context/HelloWorld": server does not support the reflection API

Does anyone have some idea?
Reply all
Reply to author
Forward
0 new messages