Spring Boot - Jpa Repository

I have encountered this below piece of code in a sample project. I couldn't understand how the findItemsById method works without defining it properly. This method was declared in the ItemsRepository interface which extends JpaRepositiry.

public interface ItemsRepo extends JpaRepository<Items,Long> {
Optional<Items> findItemsById(Long id);

And in the service class, it is defined like given below.

public Items findItemsById(Long id) throws Throwable {
    return itemsRepo.findItemsById(id).orElseThrow(()-> new UserNotFoundException("items by id "+id+" not found"));

How it is working without actual definition for findItemsById. Does declaring it as optional have any relation with this?

2 answers

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum