Table of contents
No headings in the article.
Today on the 4th day of spring boot I learned about some annotations that are following:
In Spring Boot, annotations play a significant role in configuring and customizing various aspects of your application. Here are some commonly used annotations in Spring Boot:
@SpringBootApplication
: This annotation is used to mark the main class of a Spring Boot application. It combines three annotations:@Configuration
,@EnableAutoConfiguration
, and@ComponentScan
.@Controller
: It marks a class as a controller component that handles HTTP requests and generates HTTP responses.@RestController
: It is a specialized version of@Controller
that combines the@Controller
and@ResponseBody
annotations. It is commonly used for creating RESTful web services that directly serialize the return value to the HTTP response body.@RequestMapping
: It is used to map HTTP requests to specific methods or classes. It can be applied at the class level to define a base URL mapping, and at the method level to define more specific URL mappings.@Autowired
: It is used for automatic dependency injection. It allows Spring Boot to automatically wire the dependencies of a class, eliminating the need for manual instantiation or lookup.@Value
: It is used to inject values from properties files or environment variables into variables or method arguments.@Component
: It is a generic stereotype annotation used to mark a class as a Spring component, allowing it to be detected and instantiated as a bean.@Service
: It is a specialized version of@Component
and is used to mark a class as a service component.@Repository
: It is used to mark a class as a repository component, typically for database access or data persistence.@Configuration
: It is used to indicate that a class declares one or more bean definitions. It is often used in conjunction with@Bean
methods.@EnableAutoConfiguration
: It is used to enable Spring Boot's auto-configuration feature, which automatically configures various dependencies and beans based on the classpath and other configuration properties.