๐งฐ What Youโll Learn
In this guide, weโll walk through how to:
- Generate a Spring Boot project using Spring Initializr
- Set up and understand the Maven
pom.xml
- Write your first simple REST API
- Run the project and test it
๐ ๏ธ Prerequisites
Before you start, make sure you have:
- Java 17 or 21 installed (
java -version
) - Maven installed (
mvn -v
) - An IDE like IntelliJ IDEA, Eclipse, or VS Code
โก Step 1: Generate a Spring Boot Project
Go to Spring Initializr:
- Project: Maven
- Language: Java
- Spring Boot: 3.5.x (latest stable)
- Group:
com.kscodes.springboot
- Artifact:
demo
- Name:
demo
- Description: Demo project for Spring Boot with Maven
- Packaging: Jar
- Java Version: 17 or 21
- Dependencies:
- Spring Web
Click Generate, and a .zip
file will be downloaded. Extract and open it in your IDE.

๐ฆ Step 2: Project Structure Overview
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
demo/ โโโ mvnw โโโ pom.xml โโโ src/ โ โโโ main/ โ โ โโโ java/ โ โ โ โโโ com/kscodes/springboot/demo โ โ โ โโโ DemoApplication.java โ โ โโโ resources/ โ โ โโโ application.properties โ โโโ test/ |
๐งพ Step 3: Maven pom.xml
Essentials
Here’s a simplified version of your Maven config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.kscodes.springboot</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> |
๐ก Step 4: Your First Spring Boot Application
File: DemoApplication.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.kscodes.springboot.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); } } |
๐ Step 5: Add a Simple REST Controller
File: HelloController.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.kscodes.springboot.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, World! <br>" + "Welcome to KSCodes! <br>" + "This is our first message โ a simple one, but classic:"; } } |
โถ๏ธ Step 6: Run the Application
Run the app using any of the following methods:
Method 1: From IDE
Run DemoApplication.java
as a Java application.
Method 2: From Command Line
mvnw spring-boot:run
๐ Step 7: Test Your REST Endpoint
Open your browser or use a tool like Postman:

๐ Summary
Youโve just created your first Spring Boot 3.x application using Maven. You:
- Generated a project with Spring Initializr
- Understood the Maven structure
- Built and ran a basic REST API