liveBook · Manning

@Service

As explained in Spring Start Here, Second Edition

The Spring @Service stereotype annotation marks a class as a service component eligible for detection and registration as a bean.

@Service marks a class as a service: an object responsible for implementing application use cases. Spring treats it as a stereotype annotation and adds the annotated class as a bean in its context. section 4.3

Choose the stereotype that makes a class’s responsibility clear:

  • @Service identifies service logic; @Repository identifies data persistence. Both communicate a more specific role than the generic @Component. section 4.3
  • Apply the annotation to a class, not an interface; stereotype annotations mark classes Spring should create as beans. section 4.5
@Service    #A
public class CommentService {
  // Omitted code
}

The compact example marks CommentService with @Service, making its service role explicit. section 4.3

How Spring Start Here, Second Edition covers it

How deep it goes
Defines @Service as a role marker for service logic and bean registration, without detailing annotation internals.
Examples
Uses CommentService as a service-class example and contrasts it with DBCommentRepository.
What you can do after
Apply @Service to identify service-logic classes for registration as Spring beans.
How it connects
Distinguishes @Service from @Component and @Repository, and relates stereotype annotations to the Spring context.

Also explained in

Compare how 2 books explain @Service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.