When learning Spring Boot, you will notice that many classes, methods, and fields contain annotations such as @RestController , @Service , @Autowired , and @Entity .
At first, these annotations may look confusing. But once you understand what annotations are and why we use them, Spring Boot becomes much easier to understand.
In this article, we will explore what annotations are, their advantages, and the most commonly used Spring Boot annotations in simple language.
1. What is an annotation?
An annotation is a way of providing additional information (metadata) about our Java code.
Annotations begin with the @ symbol. They can be applied to classes, methods, fields, constructors, and other elements.
For example, @Service tells Spring that a particular class is a service component. @GetMapping tells Spring which HTTP GET requests a method should handle.
Annotations don't usually perform the task themselves. Instead, frameworks like Spring read these annotations and perform the required actions.
2.β¦