I\'m currently learning Spring Boot and I\'ve seen how people create a controller, inject the service class and in the service class inject the repository.
Why do we
You don't always need a service layer. Especially if your APIs are just simple CRUD operations, for example, with no real logic required or calculations.
However, if you have an API which performs some logic before querying your repository then this should be in a separate service class. This is good practice arising from what is known as the single responsibility principle.
https://en.wikipedia.org/wiki/Single_responsibility_principle