Annotation is a core concept that works with many technologies. Annotations mean adding extra notes or remarks on something. It gives a detailed explanation of a particular part of something which is being annotated. It is used in many technologies like Java, C#, Python, Kotlin, Kubernetes, etc. Here we will discuss spring and spring-boot annotations.
Spring annotation and its types
Spring Annotations are a form of metadata that provides data about a program. Annotations are used to provide supplemental information about a program. It does not have a direct effect o the operation of the code they annotate. It does not change the action of the compiled program.
Mainly there are total 6 types of annotations:
- Spring Core Annotations
- Spring Web Annotations
- Spring Boot Annotations
- Spring Scheduling Annotations
- Spring Data Annotations
- Spring Bean annotations
Spring annotations present in the org.springframework,boot.autoconfigure and org.springframrework.boot.autoconfigure.condition packages are commonly known as Spring Boot annotations.
Spring Boot’s annotations are key to getting up to speed with the framework. They allow you to direct the framework to do the bidding, taking control and overriding its default when needed. Annotations are quick, easy to use, and ad orders of magnitude faster than building the equivalent functionality yourself.
In order to set up the initial state in the Spring Boot application, we use the @SpringBootapplication annotation. Which is a combination of @Configuration, @EnableAutoConfiguration, and @ComponentScan.
This type of annotation helps in responding to any HTTP request easily. Using various types of mapping annotations we can control how functions behave and what they return. These annotations are:
This type of annotation let you label components in your application aside from @RestController. These are functionally identical but allow you to organize your application and mark classes for specific roles helping to keep your application modular. These annotations are:
@RestController (@Controller + @ResponseBody) – not a component type
As it should SpringBoot makes it easy to write tests, identifying and fixing errors using its annotations. By testing, creating temporary services, and validating
@Bean: Dependency Injection is central to Spring Boot, and the @Bean annotation allows to make tightly coupled classes. That tells spring containers to handle their lifecycle.
@ConditionalOnJava: This annotation helps your application to run on a particular version of java. There are several other conditional annotations that apply conditions on either class, methods, WebApp, property, and many more.