
Play Store Application link β Spring Boot in 13 steps – App on Google Play
Spring Boot Introduction:
In this guide, we will walk through the basics of Spring Boot, including setting up a project and creating a simple REST API. Letβs dive straight into the code.
Github Project link – https://github.com/kuldeep101990/SpringBoot
Step 1: Setting Up a Spring Boot Project
Using Spring Initializr
- Go to https://start.spring.io/.
- Fill in the details:
- Project: Maven
- Language: Java
- Spring Boot: 3.x.x
- Dependencies: Spring Web
- Click Generate, and extract the downloaded ZIP file.
Import into IDE
- Open your IDE (e.g., IntelliJ or Eclipse).
- Import the extracted project as a Maven project.
Step 2: Writing the “Hello World” REST API
1. Main Application Class & Controller class
The main class is automatically created. Add the @RestController
annotation to make it handle HTTP requests.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Controller.java
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController
@RestController
public class Controller {
@GetMapping("/")
public String sayHello() {
return "Hello, World!";
}
}
Step 4: Running the Application
- Open the terminal in your IDE.
- Run the following command:
mvn spring-boot:run
- Alternatively, run the
DemoApplication
class directly from your IDE.
Step 5: Testing the API
- Open a browser or Postman.
- Visit the URL:
http://localhost:8080/
- You should see the response:
Hello, World!
Conclusion
Congratulations! Youβve successfully:
- Set up a Spring Boot project.
- Created a REST API.