25+ Spring and Spring Boot Annotations
2 min readSep 22, 2024
In this course, I coverred 25+ spring and spring boot annotations with line-by-line coding in IntelliJ IDEA.
In the above YouTube video course, I explained below each annotation with line-by-line coding:
- @Component Annotation: Marks a Java class as a Spring component (bean), automatically registered in the Spring context.
- @Autowired Annotation: Automatically injects dependencies into beans, used for constructor, setter, or field injection.
- @Qualifier Annotation: Helps resolve conflict when there are multiple beans of the same type by specifying which bean to inject.
- @Primary Annotation: Sets a bean as the primary candidate when multiple beans of the same type are present.
- @SpringBootApplication Annotation: Combines three annotations (@Configuration, @EnableAutoConfiguration, and @ComponentScan) to simplify Spring Boot applications.
- @Bean and @Configuration Annotations: @Bean defines a Spring-managed bean inside a @Configuration class, which is used to configure Spring beans and settings.
- @Controller, @Service, and @Repository Annotations: Used to define beans at different layers of the application: @Controller for the presentation layer, @Service for the service layer, and @Repository for the persistence layer.
- @Lazy Annotation: Defers bean creation until it is first used (lazy initialization), improving performance in certain scenarios.
- @Scope Annotation: Defines the scope of a bean, such as singleton (default), prototype, request, session, etc.
- @Value Annotation: Injects values into fields or method arguments from property files or other sources.
- @PropertySource and @PropertySources Annotations: Load properties files into the Spring Environment for configuration.
- @ConfigurationProperties Annotation: Binds external configuration properties (e.g., from a properties or YAML file) to a Java object.
- @Controller and @ResponseBody Annotations: @Controller defines a class as a Spring MVC controller, while @ResponseBody converts Java objects into JSON or XML and writes them directly to the HTTP response.
- @RestController Annotation: A specialized version of @Controller that combines it with @ResponseBody to simplify RESTful web services.
- @RequestMapping Annotation: Maps web requests to specific handler methods or classes.
- @GetMapping Annotation: Maps HTTP GET requests to specific handler methods.
- @PostMapping and @RequestBody Annotations: Maps HTTP POST requests to methods, and @RequestBody binds the request body to a method parameter.
- @PutMapping Annotation: Maps HTTP PUT requests to methods, typically used for updating resources.
- @DeleteMapping Annotation: Maps HTTP DELETE requests to methods, used for deleting resources.
- @PathVariable Annotation: Binds a method parameter to a URI template variable.
- @RequestParam Annotation: Binds a method parameter to a web request parameter.
- @EnableAutoConfiguration Annotation: Enables Spring Boot’s auto-configuration feature, which automatically configures the application based on dependencies and environment.
- @ComponentScan Annotation: Configures where to scan for components (beans) in the Spring application context.
My Top 10+ Udemy Courses (Bestseller Courses): https://www.javaguides.net/p/my-udemy-courses-ramesh-fadatare.html
Java Guides blog: https://www.javaguides.net/
Company Website: https://rameshfadatare.com/