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 aDocumentation 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.
@RestController, run the application, and package it as an executable jar — all without touching XML configuration or deploying to an external server.
Prerequisites
Before you begin, verify that you have a supported Java version installed:- Maven
- Gradle
Build your first application
Create the project structure
Create a new directory for your project and add the build file.
- Maven
- Gradle
Create a file named Verify the build works:
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
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.- Maven
- Gradle
Add the following inside the
<project> element, below the <parent> block:pom.xml
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.Write the application class
Create the directory What the annotations do:
src/main/java/com/example/ and add a file named MyApplication.java:src/main/java/com/example/MyApplication.java
@SpringBootApplication— A meta-annotation combining@SpringBootConfiguration,@EnableAutoConfiguration, and@ComponentScan.@EnableAutoConfigurationtells Spring Boot to configure the application context based on classpath jars. Becausespring-boot-starter-webmvcadded 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 thehome()method.SpringApplication.run()— Bootstraps the application, starts Spring, and launches the embedded Tomcat server.
Run the application
Start the application from your project root:You should see Spring Boot’s startup banner followed by a line like:
- Maven
- Gradle
Verify it works
Open a browser or run Press
curl against http://localhost:8080:ctrl-c in the terminal to stop the application.Package as an executable jar
Create a self-contained executable jar that you can run anywhere Java is installed.The jar file is approximately 18 MB and contains all runtime dependencies. You can inspect its contents with:
- Maven
- Gradle
Add the Spring Boot Maven plugin to your Build and run the jar:
pom.xml after the <dependencies> block:pom.xml
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.