Member-only story

Simplifying Component Definition with Spring Stereotype Annotations

Manpreet Singh
3 min readMar 29, 2023

--

Stereotype annotations are a type of annotations in the Spring Framework that are used to simplify the process of configuring and defining components in a Spring application. Stereotype annotations are a set of pre-defined annotations that can be used to mark classes as specific types of components, such as controllers, services, repositories, and others. In this article, we will explore the various stereotype annotations provided by the Spring Framework and their usage.

  1. @Controller

The @Controller annotation is used to mark a class as a Spring MVC controller. This annotation indicates that the class is responsible for handling HTTP requests and producing HTTP responses. When this annotation is used, the Spring container will create an instance of the class and register it as a controller in the web application context.

@Controller
public class MyController {
// controller methods
}

2. @Service

The @Service annotation is used to mark a class as a service in a Spring application. This annotation indicates that the class performs some business logic operations and is used by the controllers to process user requests. When this annotation is used, the Spring container will create an instance of the class and register it as a service in the application context.

@Service
public class MyService {
// service methods
}

--

--

Manpreet Singh
Manpreet Singh

Written by Manpreet Singh

Software developer who loves writing about programming, technology, passive income strategies etc.

No responses yet