Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through building a small “Hello World” web application that highlights Spring Boot’s key features. You will set up a project, add a dependency, write a @RestController, run the application, and package it as an executable jar — all without touching XML configuration or deploying to an external server.
You can skip the manual project setup by going to start.spring.io, selecting the Spring Web dependency, and generating a project archive. The steps below explain everything that the Initializr does for you.

Prerequisites

Before you begin, verify that you have a supported Java version installed:
$ java -version
openjdk version "17.0.18" 2026-01-20 LTS
OpenJDK Runtime Environment (build 17.0.18+10-LTS)
OpenJDK 64-Bit Server VM (build 17.0.18+10-LTS, mixed mode, sharing)
Java 17 or later is required. Then verify your build tool:
$ mvn -v
Apache Maven 3.9.12
Java version: 17.0.18

Build your first application

1

Create the project structure

Create a new directory for your project and add the build file.
Create a file named pom.xml in your project root. The spring-boot-starter-parent parent POM provides dependency management and useful plugin defaults — note there are no version numbers for managed dependencies.
pom.xml
<?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.0</version>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- Additional lines to be added here... -->

</project>
Verify the build works:
$ mvn package
2

Add the web starter dependency

Spring Boot starters are convenient dependency descriptors. Adding spring-boot-starter-webmvc pulls in Spring MVC, an embedded Tomcat server, and all required transitive dependencies — no version numbers required.
Add the following inside the <project> element, below the <parent> block:
pom.xml
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webmvc</artifactId>
    </dependency>
</dependencies>
Neither snippet specifies a version. spring-boot-starter-parent (Maven) and io.spring.dependency-management (Gradle) manage versions for all curated Spring Boot dependencies automatically. When you upgrade Spring Boot itself, all managed dependencies are upgraded together.
3

Write the application class

Create the directory src/main/java/com/example/ and add a file named MyApplication.java:
src/main/java/com/example/MyApplication.java
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@SpringBootApplication
public class MyApplication {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

}
What the annotations do:
  • @SpringBootApplication — A meta-annotation combining @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. @EnableAutoConfiguration tells Spring Boot to configure the application context based on classpath jars. Because spring-boot-starter-webmvc added Tomcat and Spring MVC, auto-configuration sets up a web application automatically.
  • @RestController — Marks this class as a Spring MVC controller whose methods return response bodies directly to the caller.
  • @RequestMapping("/") — Maps all HTTP requests with the path / to the home() method.
  • SpringApplication.run() — Bootstraps the application, starts Spring, and launches the embedded Tomcat server.
4

Run the application

Start the application from your project root:
$ mvn spring-boot:run
You should see Spring Boot’s startup banner followed by a line like:
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
  =========|_|==============|___/=/_/_/_/
  :: Spring Boot ::  (v3.5.0)
....... . . .
........ Started MyApplication in 0.906 seconds (process running for 6.514)
5

Verify it works

Open a browser or run curl against http://localhost:8080:
$ curl http://localhost:8080
Hello World!
Press ctrl-c in the terminal to stop the application.
6

Package as an executable jar

Create a self-contained executable jar that you can run anywhere Java is installed.
Add the Spring Boot Maven plugin to your pom.xml after the <dependencies> block:
pom.xml
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
Build and run the jar:
$ mvn package
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
The jar file is approximately 18 MB and contains all runtime dependencies. You can inspect its contents with:
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
Spring Boot uses a nested-jar approach rather than the “uber jar” pattern. This keeps library jars distinct and avoids filename conflicts when multiple dependencies include files with the same name.

What’s next

Installation

Full system requirements, Spring Initializr, Maven parent POM, Gradle plugin, and the Spring Boot CLI.

Introduction

Learn about auto-configuration, starters, embedded servers, Actuator, and native images.

Build docs developers (and LLMs) love