SlideShare a Scribd company logo
Introduction to Spring Boot
Annotations
• Annotations are metadata providing instructions to the compiler and runtime.
• Spring Boot processes annotations during component scanning and runtime.
• Techniques used: Reflection, Proxy creation, and Dependency Injection.
@SpringBootApplication
• Purpose: Marks the main class of a Spring Boot application.
• How it Works: Combines @Configuration, @EnableAutoConfiguration,
@ComponentScan.
• Code Example:
@SpringBootApplication
public class App { public static void main(String[] args)
{ SpringApplication.run(App.class, args); } }
• Use Case: Entry point for Spring Boot applications.
@RestController
• Purpose: Marks a class as a REST controller for HTTP requests.
• How it Works: Combines @Controller and @ResponseBody to return JSON or XML.
• Code Example:
@RestController
@GetMapping("/hello")
public String hello() { return "Hello!"; }
• Use Case: Creating REST APIs.
@Controller
• Purpose: Defines a class as a web controller.
• How it Works: Returns views like HTML templates.
• Code Example:
@Controller
public String home() { return "home"; }
• Use Case: Handling traditional web views.
@RequestMapping
• Purpose: Maps HTTP requests to methods.
• How it Works: Supports GET, POST, etc.
• Code Example:
@RequestMapping("/api")
public String api() { return "API Endpoint"; }
• Use Case: Organizing routes.
@GetMapping, @PostMapping,
etc.
• Purpose: Shortcut for HTTP methods.
• How it Works: Provides specific HTTP routes.
• Code Example:
@GetMapping("/items")
public List<String> getItems() { return List.of("Item1", "Item2"); }
• Use Case: Handling CRUD operations.
@Autowired
• Purpose: Injects dependencies automatically.
• How it Works: Supports field, constructor, or setter injection.
• Code Example:
@Autowired
private UserService userService;
• Use Case: Injecting services or components.
@Service
• Purpose: Marks a class as a service component.
• How it Works: Automatically registered as a Spring bean.
• Code Example:
@Service
public class UserService { }
• Use Case: Business logic components.
@Component
• Purpose: Marks a class as a Spring-managed component.
• How it Works: Included in component scanning.
• Code Example:
@Component
public class UtilityClass { }
• Use Case: Defining reusable components.
@Repository
• Purpose: Identifies data access components.
• How it Works: Manages transactions and persistence logic.
• Code Example:
@Repository
public interface UserRepository extends JpaRepository<User, Long> { }
• Use Case: Database interaction.
@Configuration
• Purpose: Declares a class as a source of bean definitions.
• How it Works: Uses @Bean methods for bean creation.
• Code Example:
@Configuration
public class AppConfig { @Bean public Service service() { return new Service(); } }
• Use Case: Centralized bean configuration.
@Bean
• Purpose: Registers a method's return value as a bean.
• How it Works: Creates beans manually.
• Code Example:
@Bean
public Service service() { return new Service(); }
• Use Case: Programmatically defining beans.
@Value
• Purpose: Injects values from configuration files.
• How it Works: Reads properties from application.properties.
• Code Example:
@Value("${app.name}")
private String appName;
• Use Case: External configuration loading.
@PathVariable
• Purpose: Binds URL path parameters.
• How it Works: Extracts variables from URLs.
• Code Example:
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) { return userService.findById(id); }
• Use Case: Handling dynamic URLs.
@RequestParam
• Purpose: Binds query parameters.
• How it Works: Reads query strings from URLs.
• Code Example:
@GetMapping("/search")
public String search(@RequestParam String q) { return "Searching for " + q; }
• Use Case: Reading query parameters.
@ResponseBody
• Purpose: Sends method return as response body.
• How it Works: Converts objects into JSON or XML.
• Code Example:
@ResponseBody
public String getData() { return "Hello, World!"; }
• Use Case: Returning JSON responses.
@RequestBody
• Purpose: Maps HTTP body to method parameter.
• How it Works: Reads input as JSON or XML.
• Code Example:
@PostMapping("/users")
public void createUser(@RequestBody User user) { userService.save(user); }
• Use Case: Handling JSON input.
@Transactional
• Purpose: Manages transactions automatically.
• How it Works: Commits or rolls back transactions.
• Code Example:
@Transactional
public void updateUser(User user) { userRepository.save(user); }
• Use Case: Managing database transactions.
@CrossOrigin
• Purpose: Enables Cross-Origin requests.
• How it Works: Allows requests from other domains.
• Code Example:
@CrossOrigin
@GetMapping("/public")
public String publicEndpoint() { return "Public Data"; }
• Use Case: Handling CORS in web apps.
@Profile
• Purpose: Activates beans for specific profiles.
• How it Works: Loads beans based on active profiles.
• Code Example:
@Profile("dev")
@Bean
public DataSource dataSource() { return new H2DataSource(); }
• Use Case: Environment-specific configurations.
Conclusion
• Spring Boot annotations simplify configuration and enable dependency injection.
• They reduce boilerplate and enhance maintainability.
• Crucial for building modern, scalable applications.

More Related Content

PDF
What's Coming in Spring 3.0
PPTX
ASP.NET - Building Web Application..in the right way!
PPTX
ASP.NET - Building Web Application..in the right way!
PDF
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
PPT
ASP.NET MVC introduction
PDF
Code igniter - A brief introduction
PDF
(ATS6-PLAT04) Query service
PDF
JAVA EE DEVELOPMENT (JSP and Servlets)
What's Coming in Spring 3.0
ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
ASP.NET MVC introduction
Code igniter - A brief introduction
(ATS6-PLAT04) Query service
JAVA EE DEVELOPMENT (JSP and Servlets)

Similar to SpringBoot_Annotations_Presentation_Refined.pptx (20)

PDF
Spring Web Services: SOAP vs. REST
PDF
Elements for an iOS Backend
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
ASP.Net 5 and C# 6
PDF
Field injection, type safe configuration, and more new goodies in Declarative...
PDF
Migrating to Jakarta EE 10
PDF
Java colombo-deep-dive-into-jax-rs
PPTX
JSP- JAVA SERVER PAGES
PPTX
ASP.NET Mvc 4 web api
PPTX
Angular or React
PPTX
GDSC NITS Presents Kickstart into ReactJS
PDF
767458168-Introduction-to-Web-API767458168-Introduction-to-Web-API.pdf.pdf
PPTX
MVC & SQL_In_1_Hour
PPTX
Lecture 4_Laravel Controller and Data Pass-Route.pptx
PPTX
Web api
PPTX
Spring 3.x - Spring MVC - Advanced topics
PPTX
StackMate - CloudFormation for CloudStack
Spring Web Services: SOAP vs. REST
Elements for an iOS Backend
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
ASP.Net 5 and C# 6
Field injection, type safe configuration, and more new goodies in Declarative...
Migrating to Jakarta EE 10
Java colombo-deep-dive-into-jax-rs
JSP- JAVA SERVER PAGES
ASP.NET Mvc 4 web api
Angular or React
GDSC NITS Presents Kickstart into ReactJS
767458168-Introduction-to-Web-API767458168-Introduction-to-Web-API.pdf.pdf
MVC & SQL_In_1_Hour
Lecture 4_Laravel Controller and Data Pass-Route.pptx
Web api
Spring 3.x - Spring MVC - Advanced topics
StackMate - CloudFormation for CloudStack
Ad

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Geodesy 1.pptx...............................................
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Sustainable Sites - Green Building Construction
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Construction Project Organization Group 2.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
composite construction of structures.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
PPT on Performance Review to get promotions
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Geodesy 1.pptx...............................................
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
bas. eng. economics group 4 presentation 1.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Sustainable Sites - Green Building Construction
UNIT 4 Total Quality Management .pptx
Foundation to blockchain - A guide to Blockchain Tech
CYBER-CRIMES AND SECURITY A guide to understanding
Construction Project Organization Group 2.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Arduino robotics embedded978-1-4302-3184-4.pdf
OOP with Java - Java Introduction (Basics)
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
composite construction of structures.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT on Performance Review to get promotions
Ad

SpringBoot_Annotations_Presentation_Refined.pptx

  • 1. Introduction to Spring Boot Annotations • Annotations are metadata providing instructions to the compiler and runtime. • Spring Boot processes annotations during component scanning and runtime. • Techniques used: Reflection, Proxy creation, and Dependency Injection.
  • 2. @SpringBootApplication • Purpose: Marks the main class of a Spring Boot application. • How it Works: Combines @Configuration, @EnableAutoConfiguration, @ComponentScan. • Code Example: @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } } • Use Case: Entry point for Spring Boot applications.
  • 3. @RestController • Purpose: Marks a class as a REST controller for HTTP requests. • How it Works: Combines @Controller and @ResponseBody to return JSON or XML. • Code Example: @RestController @GetMapping("/hello") public String hello() { return "Hello!"; } • Use Case: Creating REST APIs.
  • 4. @Controller • Purpose: Defines a class as a web controller. • How it Works: Returns views like HTML templates. • Code Example: @Controller public String home() { return "home"; } • Use Case: Handling traditional web views.
  • 5. @RequestMapping • Purpose: Maps HTTP requests to methods. • How it Works: Supports GET, POST, etc. • Code Example: @RequestMapping("/api") public String api() { return "API Endpoint"; } • Use Case: Organizing routes.
  • 6. @GetMapping, @PostMapping, etc. • Purpose: Shortcut for HTTP methods. • How it Works: Provides specific HTTP routes. • Code Example: @GetMapping("/items") public List<String> getItems() { return List.of("Item1", "Item2"); } • Use Case: Handling CRUD operations.
  • 7. @Autowired • Purpose: Injects dependencies automatically. • How it Works: Supports field, constructor, or setter injection. • Code Example: @Autowired private UserService userService; • Use Case: Injecting services or components.
  • 8. @Service • Purpose: Marks a class as a service component. • How it Works: Automatically registered as a Spring bean. • Code Example: @Service public class UserService { } • Use Case: Business logic components.
  • 9. @Component • Purpose: Marks a class as a Spring-managed component. • How it Works: Included in component scanning. • Code Example: @Component public class UtilityClass { } • Use Case: Defining reusable components.
  • 10. @Repository • Purpose: Identifies data access components. • How it Works: Manages transactions and persistence logic. • Code Example: @Repository public interface UserRepository extends JpaRepository<User, Long> { } • Use Case: Database interaction.
  • 11. @Configuration • Purpose: Declares a class as a source of bean definitions. • How it Works: Uses @Bean methods for bean creation. • Code Example: @Configuration public class AppConfig { @Bean public Service service() { return new Service(); } } • Use Case: Centralized bean configuration.
  • 12. @Bean • Purpose: Registers a method's return value as a bean. • How it Works: Creates beans manually. • Code Example: @Bean public Service service() { return new Service(); } • Use Case: Programmatically defining beans.
  • 13. @Value • Purpose: Injects values from configuration files. • How it Works: Reads properties from application.properties. • Code Example: @Value("${app.name}") private String appName; • Use Case: External configuration loading.
  • 14. @PathVariable • Purpose: Binds URL path parameters. • How it Works: Extracts variables from URLs. • Code Example: @GetMapping("/users/{id}") public User getUser(@PathVariable Long id) { return userService.findById(id); } • Use Case: Handling dynamic URLs.
  • 15. @RequestParam • Purpose: Binds query parameters. • How it Works: Reads query strings from URLs. • Code Example: @GetMapping("/search") public String search(@RequestParam String q) { return "Searching for " + q; } • Use Case: Reading query parameters.
  • 16. @ResponseBody • Purpose: Sends method return as response body. • How it Works: Converts objects into JSON or XML. • Code Example: @ResponseBody public String getData() { return "Hello, World!"; } • Use Case: Returning JSON responses.
  • 17. @RequestBody • Purpose: Maps HTTP body to method parameter. • How it Works: Reads input as JSON or XML. • Code Example: @PostMapping("/users") public void createUser(@RequestBody User user) { userService.save(user); } • Use Case: Handling JSON input.
  • 18. @Transactional • Purpose: Manages transactions automatically. • How it Works: Commits or rolls back transactions. • Code Example: @Transactional public void updateUser(User user) { userRepository.save(user); } • Use Case: Managing database transactions.
  • 19. @CrossOrigin • Purpose: Enables Cross-Origin requests. • How it Works: Allows requests from other domains. • Code Example: @CrossOrigin @GetMapping("/public") public String publicEndpoint() { return "Public Data"; } • Use Case: Handling CORS in web apps.
  • 20. @Profile • Purpose: Activates beans for specific profiles. • How it Works: Loads beans based on active profiles. • Code Example: @Profile("dev") @Bean public DataSource dataSource() { return new H2DataSource(); } • Use Case: Environment-specific configurations.
  • 21. Conclusion • Spring Boot annotations simplify configuration and enable dependency injection. • They reduce boilerplate and enhance maintainability. • Crucial for building modern, scalable applications.