Getting Started with Spring Boot

This section documents Spring Boot 4.1.x and Spring Framework 7.0.x on the Java 17/21+ baseline, as described by the official Spring Boot reference documentation and each sub-project’s own site (Spring Data, Spring for Apache Kafka, Micrometer, Project Reactor, springdoc-openapi, Spring gRPC, and the others listed in this section’s Bibliography) — which are the references these pages are written and verified against.

This content was generated with the assistance of AI and should be verified against those official docs before being relied on in production. Spring Boot and its ecosystem continue to evolve; the examples here target the current 4.1.x / 7.0.x releases.

This section’s bibliography lists the reference material consulted while preparing these pages.

This page introduces the relationship between the Spring Framework and Spring Boot, walks through generating and running a first project, and summarizes what changed for anyone coming from an older Spring Boot 2.x codebase or reference book.

Spring Framework vs. Spring Boot

The Spring Framework is the underlying dependency-injection container and programming model — beans, ApplicationContext, AOP, transaction management, and the web MVC/WebFlux stacks. It is powerful but requires explicit configuration: declaring beans, wiring a DispatcherServlet, choosing and configuring an embedded or external servlet container, and so on.

Spring Boot is an opinionated layer on top of the Framework. It does not replace it — a Spring Boot application is still a Spring ApplicationContext underneath — but it adds:

  • Auto-configuration: classes on the classpath (a JDBC driver, a servlet container, a template engine) cause Spring Boot to configure sensible beans automatically, only backing off when the developer defines their own.

  • Starters: curated dependency bundles (spring-boot-starter-webmvc, spring-boot-starter-data-jpa, …​) that pull in compatible versions of everything a feature needs.

  • An embedded server and executable jar/war, so java -jar app.jar is enough to run in production, with no separate application server to install.

  • Production-ready features (Actuator health/metrics endpoints), externalized configuration (application.yml/application.properties, environment variables, command-line arguments), and a standardized way to bootstrap the whole thing via SpringApplication.run(…​).

See spring.io for the wider Spring portfolio (Spring Framework, Spring Boot, Spring Data, Spring Security, Spring Cloud, and more) and the Spring Boot reference documentation for the canonical, version-specific description of everything in this section.

Bootstrapping a project with Spring Initializr

Spring Initializr generates a ready-to-build project skeleton (Maven or Gradle, Java or Kotlin, chosen dependencies) without hand-writing the build file from scratch. It is available as a web UI, or as a plain HTTP API that can be scripted with curl:

curl https://start.spring.io/starter.zip \
  -d type=maven-project \
  -d language=java \
  -d bootVersion=4.1.0 \
  -d javaVersion=21 \
  -d groupId=com.example \
  -d artifactId=demo \
  -d name=demo \
  -d packageName=com.example.demo \
  -d dependencies=webmvc,data-jpa,h2 \
  -o demo.zip

unzip demo.zip -d demo

Unzipping produces a Maven project with pom.xml, a DemoApplication class annotated @SpringBootApplication, an empty application.properties, and a starter test class. The same request can be issued from the web UI by picking the Maven/Gradle, language, Spring Boot version, and dependency checkboxes and clicking Generate.

$ tree demo
demo
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── example
│   │   │           └── demo
│   │   │               └── DemoApplication.java
│   │   └── resources
│   │       ├── application.properties
│   │       └── static
│   │       └── templates
│   └── test
│       └── java
│           └── com
│               └── example
│                   └── demo
│                       └── DemoApplicationTests.java

Java baseline and Maven project layout

Spring Boot 4.1.x requires Java 17 as a minimum baseline, with Java 21+ recommended for new projects (virtual threads, generational ZGC, and other JDK improvements that Spring Boot can take advantage of). The Maven layout generated above follows the standard convention:

  • pom.xml — declares the spring-boot-starter-parent (or imports the spring-boot-dependencies BOM), the chosen starters, and the spring-boot-maven-plugin used to build the executable jar.

  • src/main/java — application code, rooted at the package containing the @SpringBootApplication class so component scanning finds everything below it by default.

  • src/main/resources/application.yml (or .properties) — externalized configuration.

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>4.1.0</version>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <java.version>21</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

application.yml holds externalized configuration as structured YAML, an alternative to the flatter application.properties:

server:
  port: 8080

spring:
  application:
    name: demo
  datasource:
    url: jdbc:h2:mem:demo
    driver-class-name: org.h2.Driver

logging:
  level:
    root: INFO
    com.example.demo: DEBUG

The @SpringBootApplication entry point

@SpringBootApplication is a convenience meta-annotation combining @Configuration, @EnableAutoConfiguration, and @ComponentScan. SpringApplication.run(…​) bootstraps the ApplicationContext, triggers auto-configuration, and (when a web starter is present) starts the embedded server:

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);
    }
}

A minimal REST controller in the same package (found automatically by component scanning) confirms the application is running:

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 hello() {
        return "Hello, Spring Boot!";
    }
}

Running the application

During development, run directly from source with the Maven plugin, which also enables devtools-style restarts when spring-boot-devtools is on the classpath:

./mvnw spring-boot:run

For a deployable artifact, package and run the executable jar produced by spring-boot-maven-plugin — it bundles the application classes, all dependencies, and an embedded server into a single "fat jar":

./mvnw clean package
java -jar target/demo-0.0.1-SNAPSHOT.jar
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v4.1.0)

2026-01-10T10:00:00.000  INFO 12345 --- [demo] [main] c.e.demo.DemoApplication : Starting DemoApplication
2026-01-10T10:00:00.500  INFO 12345 --- [demo] [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http)
2026-01-10T10:00:00.600  INFO 12345 --- [demo] [main] c.e.demo.DemoApplication : Started DemoApplication in 1.2 seconds

See the Getting Started and Developing with Spring Boot chapters of the reference documentation for the full set of options (packaging as a WAR for an external container, layered Docker images via spring-boot-maven-plugin:build-image, and more).

What changed since older Spring Boot 2.x references

Anyone coming from an older Spring Boot 2.x codebase, tutorial, or local reference book should be aware of two major breaking changes introduced by later major versions — these are simply what the current Spring Boot 3/4 line does differently, not an error in any older material, which was accurate for the Spring Boot version it targeted:

The jakarta.* namespace switch (Spring Boot 3)

Spring Boot 3 moved from Java EE’s javax. packages to Jakarta EE’s jakarta. packages, following the Java EE → Jakarta EE transfer to the Eclipse Foundation. Any code, and any third-party library, written against javax.servlet., javax.persistence., or javax.validation.* needs updating for Spring Boot 3+:

<!-- Spring Boot 2.x -->
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
</dependency>

<!-- Spring Boot 3.x and 4.x -->
<dependency>
    <groupId>jakarta.validation</groupId>
    <artifactId>jakarta.validation-api</artifactId>
</dependency>

In application code this means import statements change accordingly, for example javax.persistence.Entity becomes jakarta.persistence.Entity, and javax.servlet.http.HttpServletRequest becomes jakarta.servlet.http.HttpServletRequest.

Starter renames in Spring Boot 4

Spring Boot 4 split the former all-in-one spring-boot-starter-web starter so that a project can depend on the Spring MVC stack, the Spring WebFlux stack, or a REST client independently, without pulling in more than it needs. The most common rename to know about:

<!-- Spring Boot 2.x / 3.x -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Spring Boot 4.x -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>

A project instructed by older material to add spring-boot-starter-web on Spring Boot 4.x should add spring-boot-starter-webmvc instead (or a reactive/WebFlux-oriented starter, covered in the Reactive Programming page, if the project is reactive rather than servlet-based). Always confirm current artifact names against the Developing with Spring Boot chapter, since starter names can continue to evolve across minor releases.

Next steps

With a running application in hand, the following pages in this section build on it: dependency injection and bean configuration, externalized configuration in depth, building REST APIs with Spring MVC, and testing with spring-boot-starter-test.