You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc
+25-10
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,9 @@
3
3
4
4
This section offers jumping off points for how to get started using Spring gRPC. There is a simple sample project in the `samples` directory (e.g. https://github.com/spring-projects-experimental/spring-grpc/tree/main/samples/grpc-server[`grpc-server`]). You can run it with `mvn spring-boot:run` or `gradle bootRun`. You will see the following code in that sample.
5
5
6
-
Want to get started? Let's speedrun a working service. Go to the [Spring Initializr](https://start.spring.io), select `gRPC`, `Web`, and `GraalVM`. I'll be using Apache Maven in this tutorial but Gradle works, too.
6
+
Want to get started? Let's speedrun a working service. Go to the [Spring Initializr](https://start.spring.io), select `gRPC`, `Web`, and `GraalVM`. Both Apache Maven and Gradle should work. Download the `.zip` file and unzip it. Open it in your IDE in the usual way. E.g. if you're using IntelliJ IDEA: `idea pom.xml`; or for VSCode `code .`.
7
7
8
-
If you want to use GraalVM native images, make sure you have the GraalVM distribution of OpenJDK installed. You can do so with [sdkman.io](https://sdkman.io). e.g.: `sdk install java 23.0.1-graalce && sdk default java 23.0.1-graalce`.
9
-
10
-
Download the `.zip` file and unzip it. Open it in your IDE in the usual way. If you're using IntelliJ IDEA: `idea pom.xml`.
11
-
12
-
Define a `.proto` service definition:
8
+
Define a `.proto` service definition file `src/main/proto/hello.proto` with the following contents:
13
9
14
10
[source,proto]
15
11
----
@@ -45,7 +41,14 @@ We'll want to define the stubs for a Java service based on this definition:
45
41
./mvnw clean package
46
42
----
47
43
48
-
You'll get two new folders in the `target` directory: `target/target/generated-sources/protobuf/grpc-java` and `target/target/generated-sources/protobuf/java`. You may need to instruct your IDE to mark them as source roots. In IntelliJ IDEA, you'd right click the folder, choose `Mark Directory As` -> `Generated Source Root`.
44
+
or
45
+
46
+
[source,shell]
47
+
----
48
+
./gradlew build
49
+
----
50
+
51
+
You'll get two new folders in the `target` directory (or `build` for Gradle): `target/target/generated-sources/protobuf/grpc-java` and `target/target/generated-sources/protobuf/java`. You may need to instruct your IDE to mark them as source roots. In IntelliJ IDEA, you'd right click the folder, choose `Mark Directory As` -> `Generated Source Root`. Eclipse or VSCode will add them automatically for you.
49
52
50
53
Now you can implement a service based on the generated stubs:
51
54
@@ -98,14 +101,21 @@ Run the program in the usual way:
98
101
./mvnw spring-boot:run
99
102
----
100
103
104
+
or
105
+
106
+
[source,shell]
107
+
----
108
+
./gradle bootRun
109
+
----
110
+
101
111
You can try it out using a gRPC client like `grpcurl`:
There is a default named channel (named "default") that you can configure in the same way, and then it will be used by default if there is no channel with the name specified in the channel creation.
276
+
There is a default named channel (named "default") that you can configure in the same way, and then it will be used by default if there is no channel with the name specified in the channel creation.
277
+
278
+
=== Native Images
279
+
280
+
Native images are supported for gRPC servers and clients. You can build in the https://docs.spring.io/spring-boot/how-to/native-image/developing-your-first-application.html[normal Spring Boot] way for your build tool (Maven or Gradle).
0 commit comments