Annotations in Spring Boot

Umesh Dananjaya
2 min readMay 8, 2021

Spring boot is the open-source framework. Spring boot framework use the layer architecture. Spring framework many integrated technologies these are,

  • Transaction Management.
  • Interaction with the different databases.
  • Integration with the Object Relationship frameworks.

Annotations are very important in spring we can't anything without annotations. Spring boot annotations are give us to metadata about the program. This annotations are provide a supplement information about the program. it is not the part of the application we developed annotations are mainly based on operations of the code which we help to annotate the code.

Let’s take out some annotations in spring boot.

@Required

The @Required annotation applies beans to property setter methods. It indicate the annotated bean must be populated at configuration time with the require properties. if not throws the BeanInitilizationException.

@Component

This annotation is used to detect automatically our custom beans. without having any explicit code it will scan the application for classes annotated with @component, initiate them.

@Service

This is the Specialization annotation of the @Component annotation. These annotation can used only the classed also this annotation is used to mark then class as a service provider.

@Autowired

The Autowired annotation is automatically injects the dependent beans into the references of POJO class. We can use Autowired annotation for those…

  • @Autowired on property.
  • @Autowired on the setter method.
  • @Autowired on constructor.

@RequestMapping

This is the annotation to maps the HTTP requests to handler method of MVC and REST controllers.

There are more sub mapping under the request mapping annotation those are….

  1. GET Method -used to retrieve data from the REST API.
  2. PUT Method -used to create a new resource in REST API
  3. POST Method-used to update the exiting data.
  4. DELETE Method -used to remove the relevant data.
  5. PATCH Method -used to partial update to the data

@Configuration :

This is class level annotation which is used by Spring containers as a source of bean definitions.

@ComponentScan

This is used for scan package for the beans. That annotation used with the @Configuration annotation.

@Repository

This annotation is used to to catch persistence specific exceptions and re-throw them as one of Spring’s unified unchecked exception.

--

--