Sei sulla pagina 1di 7

Spring Stereotypes

Spring Framework Stereotypes


• Stereotype - a fixed general image or set of
characteristics which represent a particular type
of person or thing.
• Spring Stereotypes are used to define Spring
Beans in the Spring context
• Available Stereotypes - @Component, @Controller,
@RestController, @Repository, @Service
Spring Framework Stereotypes
@Component

@Controller @Repository @Service

@RestController
Convenience annotation
representing @Controller
and @ResponseBody
Spring Framework Stereotypes
Annotation Description
Indicates that an annotated class is a “component” and it will
@Component be created as a bean
Indicates that an annotated class has the role of a Spring
@Controller MVC “Controller”
Convenience Annotation which extends @Controller, and
@RestController adds @ResponseBody
Indicates that an annotated class is a “Repository”, originally
defined by Domain-Driven Design (Evans, 2003) as “a
@Repository mechanism for encapsulating storage, retrieval, and search
behavior which emulates a collection of objects”
Indicates that an annotated class is a “Service”, originally
defined by Domain-Driven Design (Evans, 2003) as “an
@Service operation offered as an interface that stands alone in the
model, with no encapsulated state.”
@Repository Error Handling

Potrebbero piacerti anche