Saturday, April 2, 2022

Spring stereotype annotation

Stereotype means a fixed or general pattern.

Stereotype annotations are used to create a Spring bean automatically.

@Component

@Service

@RestController /  @Controller

@Repository

@Component is the base or generic stereotype annotation and all other annotations are derived from this one.



@Component : Used to create a Spring bean. Class define with @Component annotation auto detect and configure the bean using classpath scanning.

@Service :  This will mark your class as a service at service layer. In this class we can write business logic , transactions , third party webservice call & DAO layer interaction. 

@Controller : Indicate that this class will serve the role of controller. It will mark the class as web request handler. It is use with the combination of @RequestMapping annotation.

@Repository : Class marked with @Repository perform Data access layer, interact with DB and handle persistent related exception and re-throw as Spring unchecked exceptions.

Labels: , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home