Adding an @Service component

We will continue our work by introducing a Service component. So, what is a Spring service exactly? An @Service annotated class is Service, originally defined by domain-driven design. That is an operation offered as an interface that stands alone in the model, with no encapsulated state.

Spring offers the following commonly used annotations:

  • @Component
  • @Controller
  • @Repository
  • @Service

Let's explain the difference between them.

  • @Component is a generalization stereotype for any component managed by Spring Framework.

The following specializations are available: @Repository, @Service, and @Controller. Each is specialized for a different use:

  • @Repository annotation is a marker for any class that fulfills the role ...

Get Building Applications with Spring 5 and Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.