---
title: "A first Spring Boot web application"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/spring-boot-first-app.md
source_license: "Apache-2.0 (spring-boot docs); restated in our own words"
attribution: "Summary by iinventedlight (AI-assisted). Sources: Spring (Broadcom), Developing Your First Spring Boot Application, Apache-2.0 (spring-boot docs); Spring (Broadcom), Servlet Web Applications, Apache-2.0 (spring-boot docs)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-03
status: published
checked_on: 2026-11-03
as_of: 2026-11-03
confidence: medium
untested: "Maven, Gradle, and the sample application were not run; only the fetched Spring Boot tutorial and servlet reference pages were read."
category: coding-references
topic_area: "Java Spring Boot first app"
tags: spring-boot, java, web, maven
sources:
  - id: S1
    title: "Developing Your First Spring Boot Application"
    publisher: Spring (Broadcom)
    url: https://docs.spring.io/spring-boot/tutorial/first-application/index.html
    accessed: 2026-11-03
    license: "Apache-2.0 (spring-boot docs)"
  - id: S2
    title: "Servlet Web Applications"
    publisher: Spring (Broadcom)
    url: https://docs.spring.io/spring-boot/reference/web/servlet.html
    accessed: 2026-11-03
    license: "Apache-2.0 (spring-boot docs)"
---
# A first Spring Boot web application

## Summary
The first-application tutorial builds a small web app with Maven or Gradle. A starter brings an embedded server and Spring MVC. One class is the entry point and the controller. Auto-configuration sets the web stack up from those jars. Run it from the build tool, or package an executable jar and start it with java.

## Project and code
Check Java with `java -version`. The tutorial's sample is OpenJDK 17. Work in a fresh directory, or generate the project at start.spring.io with the Web starter.

Maven uses spring-boot-starter-parent. The tutorial pins that parent at 4.1.2, group com.example, artifact myproject. Gradle applies the Spring Boot plugin at that same version, the dependency-management plugin, and a Java toolchain of 17. Add spring-boot-starter-webmvc with no version of its own. A dependency tree then includes Tomcat and Spring Boot.

Put MyApplication under src/main/java/com/example. Mark it @RestController and @SpringBootApplication. @RequestMapping("/") returns the hello-world string. main calls SpringApplication.run. @RestController marks a web bean and writes the string back as the body. Those annotations are Spring MVC. Auto-configuration sees Tomcat and Spring MVC on the classpath and sets up a web app.

## Run, package, and the servlet layer
`mvn spring-boot:run` or `gradle bootRun` starts it. The tutorial expects the hello-world text at localhost:8080. ctrl-c stops it. Add spring-boot-maven-plugin so `mvn package` repackages an executable jar under target. `java -jar` runs that file. Gradle uses `gradle bootJar` and the jar under build/libs.

@Controller or @RestController beans handle HTTP, mapped with @RequestMapping. Do not combine MVC auto-configuration with @EnableWebMvc. Static files come from /static, /public, /resources, or /META-INF/resources. The embedded server listens on port 8080. Tomcat and Jetty are the embedded containers. A single servlet bean maps to /. Filters map to /*.

## Claims
- id: C1
  claim: The first application can be built with either Maven or Gradle.
  source: S1
  evidence: "You can choose between Maven or Gradle as the build system."
- id: C2
  claim: Starters add the jars you are likely to need for one kind of application onto the classpath.
  source: S1
  evidence: "Spring Boot provides a number of starters that let you add jars to your classpath."
- id: C3
  claim: SpringApplication.run starts Spring, which then starts the auto-configured Tomcat web server.
  source: S1
  evidence: "SpringApplication bootstraps our application, starting Spring, which, in turn, starts the auto-configured Tomcat web server."
- id: C4
  claim: An executable jar is produced for Maven by adding the spring-boot-maven-plugin to the POM.
  source: S1
  evidence: "To create an executable jar, we need to add the spring-boot-maven-plugin to our pom.xml"
- id: C5
  claim: Spring MVC controller beans handle incoming HTTP requests, and @RequestMapping maps methods to those requests.
  source: S2
  evidence: "Spring MVC lets you create special @Controller or @RestController beans to handle incoming HTTP requests."
- id: C6
  claim: Spring Boot MVC auto-configuration takes the place of @EnableWebMvc, and you should not turn both on.
  source: S2
  evidence: "It replaces the need for @EnableWebMvc and the two cannot be used together."
- id: C7
  claim: By default the embedded servlet server accepts HTTP on port 8080.
  source: S2
  evidence: "By default, the embedded server listens for HTTP requests on port 8080"
