Add servlet server starter module

This adds a starter module that includes the Spring gRPC server
starter and the required dependencies ((`spring-boot-starter-web`
and `jakarta-grpc-servlet`) to use the servlet container as a
gRPC server.

Signed-off-by: Chris Bono <chris.bono@gmail.com>
This commit is contained in:
Chris Bono
2025-02-07 12:37:18 -06:00
parent 2bd167e985
commit 4c1ee098f9
4 changed files with 48 additions and 13 deletions

View File

@@ -21,6 +21,7 @@
<module>spring-grpc-spring-boot-autoconfigure</module>
<module>spring-grpc-spring-boot-starter</module>
<module>spring-grpc-client-spring-boot-starter</module>
<module>spring-grpc-server-web-spring-boot-starter</module>
<module>samples</module>
</modules>

View File

@@ -75,6 +75,16 @@
<artifactId>spring-grpc-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-client-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-server-web-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Utilities -->
<dependency>
<groupId>org.springframework.grpc</groupId>

View File

@@ -59,21 +59,15 @@ dependencies {
== Servlet Server
Any servlet container can be used to run a gRPC server.
Spring gRPC includes autoconfiguration that configures the server to use the servlet container if it detects that it is in a web application, so all you have to do is include `spring-boot-starter-web` and the `grpc-servlet` dependnecy in your application.
Spring gRPC includes autoconfiguration that configures the server to use the servlet container if it detects that it is in a web application.
Spring gRPC also provides a convenience starter that includes the required dependencies (`spring-boot-starter-web` and the `grpc-servlet-jakarta`) for this scenario.
So all you have to do is include the `spring-boot-starter-web` dependency as follows:
[source,xml]
----
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-servlet-jakarta</artifactId>
<artifactId>spring-grpc-server-web-spring-boot-starter</artifactId>
</dependency>
----
@@ -82,9 +76,7 @@ For Gradle users
[source,gradle]
----
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.grpc:spring-grpc-spring-boot-starter"
implementation "io.grpc:grpc-servlet-jakarta"
implementation "org.springframework.grpc:spring-grpc-server-web-spring-boot-starter"
}
----

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc</artifactId>
<version>0.4.0-SNAPSHOT</version>
</parent>
<artifactId>spring-grpc-server-web-spring-boot-starter</artifactId>
<packaging>jar</packaging>
<name>Spring gRPC Servlet Server Spring Boot Starter</name>
<description>Spring gRPC Servlet Server Spring Boot Starter</description>
<dependencies>
<dependency>
<groupId>org.springframework.grpc</groupId>
<artifactId>spring-grpc-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-servlet-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
</project>