Hello World Program in Spring Boot admin, January 30, 2025January 31, 2025 1. Setup a Spring Boot Project You can set up a Spring Boot project using: Spring Initializr (Recommended) Manually (Maven or Gradle) Using Spring Initializr Go to Spring Initializr Select the following: Project: Maven or Gradle Language: Java Spring Boot Version: Latest Stable (e.g., 3.x) Dependencies: Add Spring Web Click Generate and download the project. Extract and open it in an IDE (IntelliJ, Eclipse, VS Code). 2. Create the Main Application Class Spring Boot applications start with a class annotated with @SpringBootApplication. Main Class (HelloWorldApplication.java) package com.example.helloworld; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HelloWorldApplication { public static void main(String[] args) { SpringApplication.run(HelloWorldApplication.class, args); } } 3. Create a REST Controller Now, create a REST API to return “Hello, World!”. Controller (HelloController.java) package com.example.helloworld; import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestControll @RestController @RequestMapping(“/api”) public class HelloController { @GetMapping(“/hello”) public String sayHello() { return “Hello, World!”; } } 4. Run the Application Open a terminal in your project folder and run: mvn spring-boot:run OR (if using Gradle) gradle bootRun You should see logs indicating the server has started on port 8080. 5. Test the API Open a browser or use Postman and visit: bash http://localhost:8080/api/hello Output: Hello, World! Bonus: Running as a JAR You can package and run your Spring Boot application as a JAR: mvn clean package java -jar target/helloworld-0.0.1-SNAPSHOT.jar Spring Boot