0
0
Spring Bootframework~30 mins

@RestController annotation in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the @RestController Annotation in Spring Boot
📖 Scenario: You are building a simple web service that responds with greeting messages. This service will use Spring Boot to create a REST API endpoint.
🎯 Goal: Create a Spring Boot REST controller using the @RestController annotation that returns a greeting message when accessed via HTTP GET.
📋 What You'll Learn
Create a Spring Boot application class
Create a controller class annotated with @RestController
Add a method that handles GET requests at path /greet
Return a plain text greeting message from the method
💡 Why This Matters
🌍 Real World
REST controllers are used to build web services that communicate over HTTP, commonly used in web and mobile apps.
💼 Career
Understanding @RestController is essential for backend developers working with Spring Boot to create APIs.
Progress0 / 4 steps
1
Create the Spring Boot application class
Create a class called GreetingApplication annotated with @SpringBootApplication and add the main method that runs SpringApplication.run(GreetingApplication.class, args).
Spring Boot
Need a hint?

The main class needs the @SpringBootApplication annotation and a main method to start the app.

2
Create the REST controller class
Create a class called GreetingController and annotate it with @RestController.
Spring Boot
Need a hint?

The controller class must have the @RestController annotation above the class declaration.

3
Add a GET method to return a greeting
Inside the GreetingController class, add a method called greet annotated with @GetMapping("/greet") that returns the string "Hello, Spring Boot!".
Spring Boot
Need a hint?

The method should be public, return a String, and have the @GetMapping("/greet") annotation.

4
Complete the REST controller setup
Ensure the GreetingController class imports org.springframework.web.bind.annotation.GetMapping and that the class and method are properly structured to serve the greeting at /greet.
Spring Boot
Need a hint?

Make sure all necessary imports are present and the class and method annotations are correct.