Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2025 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

1. Overview

In this tutorial, we’ll explore how to utilize the Spring gRPC project to build a Spring application that includes a gRPC server. Using this project provides us with all the usual Spring benefits, such as fast development and dependency injection, as well as a straightforward way to build gRPC servers, messages, and clients.

2. Project Setup

First, we’ll use the Spring Initializr to get an example project. We only need to select Spring gRPC from the list of dependencies. After opening up the downloaded folder in our development environment, we should find a pom.xml with the dependencies we need. There’ll also be an Application.java file, which contains our application’s main method. Helpfully, there’s also a folder called proto created for us, which we’ll use in the next section.

If we wanted to add a gRPC server to an existing application, we’d need to add the following dependencies:

<dependency>
    <groupId>io.grpc</groupId>
    <artifactId>grpc-services</artifactId>
    <version>1.72.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.grpc</groupId>
    <artifactId>spring-grpc-spring-boot-starter</artifactId>
    <version>0.8.0</version>
</dependency>

We should also keep in mind that Spring gRPC currently supports Spring Boot 3.4.x and 3.5.x.

On top of the dependencies, we’ll need a build plugin to generate classes and interfaces from our Proto file. The tool provided automatically by the Spring Initializr is protobuf-maven-plugin, but others are available and would also work.

Let’s add the plugin to our pom:

<plugin>
    <groupId>org.xolstice.maven.plugins</groupId>
    <artifactId>protobuf-maven-plugin</artifactId>
    <version>0.6.1</version>
    <configuration>
        <protocArtifact>com.google.protobuf:protoc:4.30.2:exe:${os.detected.classifier}</protocArtifact>
        <pluginId>grpc-java</pluginId>
        <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.72.0:exe:${os.detected.classifier}</pluginArtifact>
    </configuration>
    <executions>
        <execution>
            <id>compile</id>
            <goals>
                <goal>compile</goal>
                <goal>compile-custom</goal>
            </goals>
            <configuration>
                <pluginParameter>jakarta_omit,@generated=omit</pluginParameter>
            </configuration>
        </execution>
    </executions>
</plugin>

3. Defining a Proto File

Now we’ve got our basic application structure, let’s start creating our gRPC server and messages. We’ll create a basic calculator that performs only one operation: multiplying two numbers.

To get started, in our proto folder generated in step 2, let’s create a new file called calculator.proto. At the top, we need to set the syntax and a few options:

syntax = "proto3";

option java_multiple_files = true;
option java_package = "org.springframework.grpc.calculator.proto";
option java_outer_classname = "CalculatorProto";

The syntax line specifies that we want to use the proto3 revision of the Protocol Buffers language.

The options are all instructions for how we want our generated Java code to be named and structured. The java_multiple_files line tells the compiler to create a separate Java file for each service and message we describe. The java_package option states where to put the generated files. Finally, the java_outer_classname option determines the name of the Wrapper class, which will be the Java representation of our Proto file.

Following on from that, we can now define a Request message that’ll contain the two numbers we’ll multiply:

message Request {
  int32 firstValue = 1;
  int32 secondValue = 2;
}

We then need a Response message to send back after we perform the calculation. This should only have one field, the result:

message Response {
  int32 result = 1;
}

Finally, now we’ve got our inputs and outputs, we can define our service:

service Calculator {
  rpc Multiply(Request) returns (Response) {}
}

This service is called Calculator; it has one method called Multiply, which takes a Request and returns a Result.

4. Using the Proto File to Generate Service and Message Interfaces

We’ve defined the basic outline of our gRPC functionality. Now, we can generate the required source files from our Proto file by running:

./mvnw clean package

Within a target folder, this will generate concrete implementations of our messages in classes called Request and Response. It’ll also create an abstract class we can extend for our service called CalculatorGrpc.CalculatorImplBase. Within this abstract class, we have a stubbed version of our Multiply method that we’ll need to override and implement fully.

5. Implementing a Concrete Service

The next step is to extend the generated base class and properly implement our Multiply method. Let’s create a Service class named GrpcCalculatorService that extends CalculatorGrpc.CalculatorImplBase:

@Service
public class GrpcCalculatorService extends CalculatorGrpc.CalculatorImplBase {}

We can now override the Multiply method and add the code to do the multiplication:

@Override
public void multiply(Request req, StreamObserver<Response> responseObserver) {
    Response reply = Response.newBuilder().setResult(req.getFirstValue() * req.getSecondValue()).build();
    responseObserver.onNext(reply);
    responseObserver.onCompleted();
}

The method signature gives us a Request, which is the object we defined in our Proto file. It also gives us a StreamObserver to pass our Response into.

The first step is to build a Response object that contains the result of the calculation. We’ve done that using the automatically provided builder methods to create the object and put the correct number into the result field. Secondly, we use the onNext() method to send the Response. Finally, we can tell the StreamObserver that we are finished with the onCompleted() method.

6. Running and Testing the Service

We have the usual options to run our service. We can run it through our IDE using the main method in Application.java. Alternatively, we can run it from the command line:

./mvnw spring-boot:run

Once the application is successfully up and running, we can call our service and check that it works. The simplest way to do that is through the command line again. We need a gRPC tool for this. The option that we’ll use here is gRPCurl, but other options are available. An example call to our Calculator service looks like this:

grpcurl -d '{"firstValue":7, "secondValue":6}' -plaintext localhost:9090 Calculator.Multiply

Here we’re using the -d flag to pass in our Request message with the two values we want to multiply. We’ve also passed in the URL, in this case localhost on port 9090, but we could change that in our application.properties file if desired. And finally, we’ve specified the service and method we want to use to process our request. The service should respond:

{
  "result": 42
}

5. Conclusion

In this tutorial, we’ve explored the basic usage of the Spring gRPC project. We started by setting up a small project using the Spring Initializr and used a Proto file to define the structure of our services and messages. We then automatically built the majority of the required code and interfaces using a Maven build plugin.

Following on from that, we implemented the generated interface to create a fully functional instance of our Calculator service. Finally, we tested the gRPC server from the command line and successfully multiplied two numbers.

This is a quick and easy way to get a gRPC server up and running with minimal code and full integration into the Spring ecosystem.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Course – Black Friday 2025 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2025 – NPI (All)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments