Category: java
how to create spring boot and run the app
Published on 01 Apr 2026
Explanation
Step 1: Install Required Tools π οΈ β
Before creating a Spring Boot app, make
sure Java (JDK 17+ recommended), Maven (or
Gradle), and an IDE like IntelliJ IDEA
or VS Code are installed.
Code:
java -version mvn -version
Explanation
Step 2: Create a Spring Boot Project
π β Use Spring Initializr
(https://start.spring.io/) and
select Project: Maven, Language:
Java, Spring Boot
Version: Latest stable,
Dependencies: Spring Web.
Download and extract the project.
Code:
Group: com.example Artifact: demo Dependencies: Spring Web
Explanation
Step 3: Main Application Class βΆοΈ β
This is the entry point of your
Spring Boot application.
The @SpringBootApplication
annotation enables
auto-configuration and component scanning.
Code:
package com.example.demo;
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);
}
}
Explanation
Step 4: Create a REST Controller π
β Add a simple controller class to
handle HTTP requests and return a response.
Code:
package com.example.demo;
import org.springframework.web.bind.
annotation.GetMapping;
import org.springframework.web.bind.
annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello Spring Boot!";
}
}
Explanation
Step 5: Run the Application βΆοΈ β
Open terminal in the project folder and
run the Spring Boot app using Maven.
Code:
mvn spring-boot:run
Explanation
Step 6: Test the Application β
β
Open a browser and visit the endpoint
below. You should see the response from
your controller.
Code:
http://localhost:8080/hello