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 – 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 – 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

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 – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Overview

In this tutorial, we’ll look at the new repository interfaces introduced in Spring Data 3.

Spring Data 3 introduced List-based CRUD repository interfaces, which can be used to replace existing CRUD repository interfaces that return Iterable. In addition, the paging and sorting interfaces don’t inherit from original CRUD repositories by default and instead leave that option to the user. We’ll see how these interfaces differ from the existing interfaces and how to use them.

2. Project Setup

Let’s start by setting up our project. We’ll create a Spring Boot application containing a simple entity and repositories that will use the new interfaces.

2.1. Dependencies

Let’s start by adding the required dependencies to our project. We’ll add the Spring Boot Starter Data dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>3.1.5</version>
</dependency>

In addition to this, we’ll configure the database. Any SQL database can be used. We’ll use the in-memory H2 database for this tutorial. Let’s add a dependency for the same:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>

2.2. Entity

Let’s create an entity Book that we’ll use in our repositories:

@Entity
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    private String author;
    private String isbn;

    // Constructor, getters and setters
}

Now that we have our entity, let’s look at how to use the new interfaces to interact with the database.

3. List-based CRUD Repositories

Spring Data 3 introduces a new set of CRUD repository interfaces that return a list of entities. These interfaces are similar to the existing interfaces, except they return a List instead of an Iterable. This enables us to use advanced methods from the List interface, such as get() and indexOf().

3.1. List-based Repository Interfaces

Three new interfaces have been added to Spring Data 3.

The ListCrudRepository interface provides methods for basic CRUD operations such as save()delete(), and findById(). The key difference between ListCrudRepository and its Iterable-based counterpart is that the returned values are now lists, which allows us to perform more advanced operations on the returned data.

The ListQuerydslPredicateExecutor interface provides methods for executing queries using Querydsl predicates. Querydsl is a framework that allows us to build type-safe SQL-like queries in Java. With ListQuerydslPredicateExecutor, we can execute Querydsl queries and return the results as a list.

The ListQueryByExampleExecutor interface provides methods for executing queries using example entities and returns the results as a list. An example entity is an entity that contains the values that we want to use to search for other entities. For example, if we have a Book entity with the title Spring Data, we can create an example entity with the title Spring Data and use it to search for other books with the same title.

3.2. ListCrudRepository

Let’s look at the ListCrudRepository interface in detail. We’ll create a repository that will use this interface to interact with the database:

@Repository
public interface BookListRepository extends ListCrudRepository<Book, Long> {
    
    List<Book> findBooksByAuthor(String author);
}

The above repository extends the ListCrudRepository interface, which provides us with the basic CRUD methods. We can use the existing repository methods to save, delete, and find books in the database.

In addition to these methods, we defined the findBooksByAuthor() method to find books by their author.

3.3. Using List-based Repository Interfaces

Let’s look at how we can use this repository to interact with the database:

@SpringBootTest
public class BookListRepositoryIntegrationTest {

    @Autowired
    private BookListRepository bookListRepository;
    
    @Test
    public void givenDbContainsBooks_whenFindBooksByAuthor_thenReturnBooksByAuthor() {
        Book book1 = new Book("Spring Data", "John Doe", "1234567890");
        Book book2 = new Book("Spring Data 2", "John Doe", "1234567891");
        Book book3 = new Book("Spring Data 3", "John Doe", "1234567892");
        bookListRepository.saveAll(Arrays.asList(book1, book2, book3));

        List<Book> books = bookListRepository.findBooksByAuthor("John Doe");
        assertEquals(3, books.size());
    }
}

We first created three books and saved them to the database. Then, we used the findBooksByAuthor() method to find all the books by the author John Doe. At last, we verified that the returned list contains the three books that we created.

Please note that we called the size() method on the returned list. This wouldn’t have been possible if the repository had used the Iterable-based interfaces because the Iterable interface doesn’t provide a size() method.

4. Sorting Repositories

To be able to use the new List-based interfaces, Spring Data 3 had to make changes to the existing sorting interfaces. The sorting repositories don’t extend the older crud repositories anymore. Instead, the user has the option to extend the new List-based interfaces or the Iterable-based interfaces along with the sorting interfaces. Let’s look at how we can use the latest sorting interfaces.

4.1. PagingAndSortingRepository

Let’s look at the PagingAndSortingRepository interface in detail. We’ll create a repository that will use this interface to interact with the database:

@Repository
public interface BookPagingAndSortingRepository extends PagingAndSortingRepository<Book, Long>, ListCrudRepository<Book, Long> {
    
    List<Book> findBooksByAuthor(String author, Pageable pageable);
}

The above repository extends the ListCrudRepository interface, which provides us with the basic CRUD methods. In addition to this, we extended the PagingAndSortingRepository interface, which provides us with methods for sorting and pagination.

In older versions of Spring Data, we didn’t need to extend a CRUD repository interface explicitly. Only the sorting and pagination interfaces were enough. We’ve defined a new method called findBooksByAuthor() that takes a Pageable parameter and returns a list of books. In the next section, we’ll look at how we can use this method to sort and paginate the results.

4.2. Using Sorting Repository Interfaces

Let’s look at how we can use this repository to interact with the database:

@SpringBootTest
public class BookPagingAndSortingRepositoryIntegrationTest {

    @Autowired
    private BookPagingAndSortingRepository bookPagingAndSortingRepository;
    
    @Test
    public void givenDbContainsBooks_whenfindBooksByAuthor_thenReturnBooksByAuthor() {
        Book book1 = new Book("Spring Data", "John Doe", "1234567890");
        Book book2 = new Book("Spring Data 2", "John Doe", "1234567891");
        Book book3 = new Book("Spring Data 3", "John Doe", "1234567892");
        bookPagingAndSortingRepository.saveAll(Arrays.asList(book1, book2, book3));

        Pageable pageable = PageRequest.of(0, 2, Sort.by("title").descending());
        List<Book> books = bookPagingAndSortingRepository.findBooksByAuthor("John Doe", pageable);
        assertEquals(2, books.size());
        assertEquals(book3.getId(), books.get(0).getId());
        assertEquals(book2.getId(), books.get(1).getId());
    }
}

Just like before, we first created three books and saved them to the database. Then, we used the findBooksByAuthor() method to find all the books by the author John Doe. But this time, we passed a Pageable object to the method to sort the results by the title in descending order and to return only the first two results.

At last, we verified that the returned list contains the two books that we created. We also verified that the books are sorted by the title in descending order so that the book with the title Spring Data 3 is returned first and the book with the title Spring Data 2 is returned second.

4.3. Other Sorting Interfaces

In addition to the PagingAndSortingRepository interface, the below interfaces have also been changed:

  • ReactiveSortingRepository no longer inherits from ReactiveCrudRepository
  • CoroutineSortingRepository no longer inherits from CoroutineCrudRepository
  • RxJavaSortingRepository no longer inherits from RxJavaCrudRepository

5. Conclusion

In this article, we explored the new List-based interfaces that have been added to Spring Data 3. We looked at how to use these interfaces to interact with the database. We also looked at the changes that have been made to the existing sorting interfaces to be able to use the new List-based interfaces along with them.

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.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

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.

eBook Jackson – NPI EA – 3 (cat = Jackson)