SpringBoot Annotations

Before proceeding further let us first understand some important annotations of Spring Boot.

@SpringBootApplication: annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes.  One thing to note here regarding ComponentScan is, @SpringBootApplication scans only the subpackages. i.e. for example if the main class is in com.javainfinite, then it will scan all classes from com.javainfinite.* packages.

@EnableAutoConfiguration: attempting to guess and configure beans. If we use SpringBootApplication this annotation is auto enabled and has no effect adding it again

@Controller: marks as web application controller

@RestController: works same as @Controller annotation except @ResponseBody is active by default. In case of @Controller we need to declare @ResponseBody.

@ResponseBody: returns value to the response as HTTP Response body

@RequestMapping: to map the URL for the particular method of entire class

@RequestParam: accessing query parameter values from the request

@PathVariable: pattern that is used in the URI for the incoming request

There are various other annotations too, above explained annotations are the ones most commonly used in springboot.

By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *