Spring Boot is a way to build Java applications with almost no setup: you add one dependency, write a class with main, and you have a running web server. It does this by looking at what is on your classpath and configuring Spring (the framework underneath) to match. This tutorial takes you from nothing to a working REST endpoint, then hands you a map of 82 deeper guides on this site, grouped by what you want to do next.
| You will learn | Section |
|---|---|
| What you need installed | 1 |
| The smallest app that runs | 2 |
| How a request becomes a response | 3 |
| Layers: controller, service, repository | 4 |
| Configuration and validation | 5 |
| Where to go next (map of 82 guides) | 6 |
Tested on Spring Boot 4.1.1, Java 21 (OpenJDK 21.0.12), Maven. Every output block below is from a real run of the demo app: DemoApplication.java, Components.java and More.java. Boot 4 needs Java 17 or newer; on a new project use the latest LTS (Java 21 or 25). Check Spring Boot versions for support dates.
1. What you need
A JDK (Java 21 is a good choice), Maven or Gradle, and an editor. Check with java -version and mvn -v. To create a project, either use start.spring.io (pick Maven, Java, Spring Boot 4.1.x, and the Spring Web dependency) or copy the pom from spring-boot-annotation-demo-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>4.1.1</version>
<relativePath/>
</parent>
<groupId>demo</groupId>
<artifactId>demo</artifactId>
<version>1.0.0</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-validation</artifactId></dependency>
</dependencies>
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>Source: spring-boot-annotation-demo-pom.xml. Notice there is no version on the dependencies. The spring-boot-starter-parent parent chooses compatible versions for you, and a starter such as spring-boot-starter-webmvc pulls in everything needed for web apps (Spring MVC, Tomcat, JSON). The Spring vs Spring Boot vs Spring MVC post measures what that saves.
2. The smallest app that runs
One class is enough. @SpringBootApplication turns on component scanning and auto-configuration; SpringApplication.run starts the container and the embedded server:
package 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);
}
}Source: DemoApplication.java. Run it with mvn spring-boot:run or build the jar and run java -jar. The lines that matter in the startup log:
2026-10-21T21:33:55.071+05:30 INFO 1569 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.24]
2026-10-21T21:33:55.665+05:30 INFO 1569 --- [ main] o.s.boot.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2026-10-21T21:33:55.679+05:30 INFO 1569 --- [ main] demo.DemoApplication : Started DemoApplication in 2.705 seconds (process running for 3.357)Tomcat is up on port 8080, started inside your own process; there is no separate server to install. The three annotations hiding in @SpringBootApplication are listed with real output in the annotations list.
3. How a request becomes a response
A client sends HTTP to Tomcat. Spring MVC’s DispatcherServlet looks at the URL and calls the matching controller method. The controller asks a service, the service asks a repository, and the return value travels back as the response. Each box is an ordinary class. Spring creates them, and hands each one the next as a constructor argument (dependency injection).
4. Controller, service, repository
Start from the bottom. The repository returns data (here a fixed list), the service uses it, and the controller exposes it. Mark each with its stereotype annotation so Spring finds and creates them:
@Repository
class ItemRepository {
List<String> findAll() { return List.of("pen", "book", "lamp"); }
}
@Service
class ItemService {
private final ItemRepository repo;
ItemService(ItemRepository repo) { this.repo = repo; }
List<String> items() { return repo.findAll(); }
}Source: Components.java. ItemService asks for an ItemRepository in its constructor and Spring supplies it. That is all that dependency injection is. Prefer constructor injection; Dependency Injection in Spring Boot 4: Constructor vs Setter vs Field (and Why Field Injection Hurts) shows why field injection hurts.
@RestController
@RequestMapping("/api")
class ItemController {
private final ItemService service;
private final Notifier primary;
private final Notifier sms;
private final AppProps props;
@Value("${app.greeting}") String greeting;
ItemController(ItemService service, Notifier primary, @Qualifier("sms") Notifier sms, AppProps props) {
this.service = service; this.primary = primary; this.sms = sms; this.props = props;
}
@GetMapping("/items")
List<String> items() { return service.items(); }
@GetMapping("/items/{index}")
String one(@PathVariable int index, @RequestParam(defaultValue = "plain") String style) {
return style + ":" + service.items().get(index);
}
// ...other handlers in the file
}Source: Components.java. @RestController says return values are the response body. Try it:
$ curl localhost:8080/api/items
["pen","book","lamp"]
$ curl localhost:8080/api/items/1?style=bold
bold:book{index} in the path is a path variable and style is a query parameter, and Spring converted 1 to an int for you. Pass something that is not a number and you get a 400, not a 500:
$ curl localhost:8080/api/items/abc
{"timestamp":"2026-10-21T16:04:04.715Z","status":400,"error":"Bad Request","path":"/api/items/abc"}
HTTP 4005. Configuration and validation
Settings live in src/main/resources/application.properties. The demo has two lines, app.greeting and app.max-items, read two ways: @Value for one property and a @ConfigurationProperties record for the group:
$ curl localhost:8080/api/config
{"props.maxItems":5,"value":"Hello from properties","props.greeting":"Hello from properties"}Source: Components.java. Profiles, config import and environment variables are in Spring Boot Profiles Done Right: Config Import, Config Trees and Kubernetes ConfigMaps and @ConfigurationProperties vs @Value in Spring Boot 4: Binding, Validation and Relaxed Rules.
Reject bad input at the edge with Bean Validation: put @Valid on the @RequestBody and constraints on the record. The invalid body below never reaches your method:
$ curl -XPOST -H "Content-Type: application/json" -d {"name":"","qty":0} localhost:8080/api/new
{"timestamp":"2026-10-21T16:04:04.682Z","status":400,"error":"Bad Request","path":"/api/new"}
HTTP 400Source: More.java. By default the 400 body does not say which field failed; Global Exception Handling with ProblemDetail (RFC 9457) in Spring Boot 4 shows how to return a proper error document.
6. Where to go next
Everything below is a tested guide on this site. Pick the section that matches what you are building. If you do not know yet, do the first two groups, then the project structure and CRUD with MySQL posts, then build one of the 10 project ideas or the microservices project.
Core concepts: beans, injection, configuration
- Dependency Injection in Spring Boot 4: Constructor vs Setter vs Field (and Why Field Injection Hurts)
- @Autowired Explained: By-Type Resolution, @Qualifier, @Primary, ObjectProvider and List Injection
- Spring Bean Scopes: Singleton, Prototype, Request, Session and the Prototype-in-Singleton Trap
- Spring Bean Lifecycle in Boot 4: @PostConstruct, InitializingBean, SmartLifecycle and Shutdown Order
- Circular Dependencies in Spring Boot 4: Why Startup Fails and 4 Ways to Fix It
- @ConfigurationProperties vs @Value in Spring Boot 4: Binding, Validation and Relaxed Rules
- Spring Boot Profiles Done Right: Config Import, Config Trees and Kubernetes ConfigMaps
- Write Your Own Spring Boot 4 Starter: Auto-Configuration, @Conditional and Properties
- Spring Application Events: @EventListener, @TransactionalEventListener and Async Events
- Internationalization (i18n) in Spring Boot 4: MessageSource, LocaleResolver and Localized ProblemDetail
Building REST APIs
- Building Your First Spring RESTful API: A “Hello World” Guide
- Building a REST API with Spring Boot: Complete Beginner’s Guide
- Global Exception Handling with ProblemDetail (RFC 9457) in Spring Boot 4
- Custom Validation in Spring Boot: Beyond the Basics!
- springdoc-openapi with Spring Boot 4.1: Generating, Customising and Versioning Your API Spec
- Spring GraphQL 2.0: Schema-First APIs, DataLoader Batching and Killing N+1
- Spring Boot 4 HTTP Service Clients: Build REST Clients with Just an Interface
- RestClient vs WebClient vs HTTP Interface Clients in Spring Boot 4.1: Which to Use
- File Upload and Download in Spring Boot 4: Multipart, Streaming and S3 Presigned URLs
- Server-Sent Events and WebSocket on Spring Boot 4: SseEmitter, STOMP, and Which to Pick
- Mastering Cache Control with ETag in Spring Boot RESTful APIs
Data and persistence
- Spring Data JDBC vs Spring Data JPA in 2026: When Dropping the ORM Is the Right Call
- Flyway vs Liquibase for Spring Boot 4: Migrations, Rollbacks and Baselines
- Zero-Downtime Database Migrations: Expand-Contract in Practice with Spring Boot
- Multiple DataSources in Spring Boot 4 with Spring Data JPA
- @Transactional in Spring: Propagation, Isolation, and the Six Ways It Silently Does Nothing
- @DataJpaTest in Spring Boot 4.1 with Testcontainers @ServiceConnection
- Spring Data JPA 3 to 4 Migration Guide: What Breaks, What Changes, and What Stays the Same
- Redis with Spring Boot 4.1: RedisTemplate vs StringRedisTemplate, @RedisHash, Pub/Sub and TTL
- Spring Data Redis JsonOperations: Partial Reads and Writes on JSON Documents
- Spring Boot 4 with MongoDB: Transactions, Aggregations and Indexes That Actually Work
- Full-Text Search with Spring Data Elasticsearch on Spring Boot 4
- Distributed Caching in Spring Boot: Hazelcast vs Infinispan vs Redis
- The Spring Cache Abstraction: @Cacheable, @CacheEvict, Key Generators and the Self-Invocation Trap
Messaging, async and batch
- Spring Boot 4.1 and Apache Kafka: Producer, Consumer and Serialisation from Scratch
- Spring Boot and RabbitMQ: Exchanges, Queues, Bindings and a Working Dead-Letter Queue
- Kafka Error Handling with Spring Kafka 4.1: DLT, Retry Topics and Poison Pills
- @Async in Spring Boot 4: Executors, Virtual Threads and the Self-Invocation Trap
- @Scheduled, ShedLock and Distributed Cron: Scheduling That Survives Three Replicas
- Background Jobs in Spring Boot 4 with JobRunr 9
- Spring Batch on Boot 4.1: Jobs, Steps, Chunk Processing and Restartability
- Spring Batch Partitioning and Parallel Steps: Scaling a 10-Million-Row Job
- Kafka vs RabbitMQ vs Pulsar for Java Teams: A Decision Framework with Benchmarks
Security
- Spring Security 7.1 JWT Authentication: The Complete Guide (Spring Boot 4.1)
- Spring Security OAuth2 Resource Server: JWT Validation, JWKS and Key Rotation
- Spring Authorization Server: Running Your Own OAuth2 / OIDC Provider (Spring Boot 4.1)
- The Spring Security Filter Chain Explained: Every Filter, In Order, and How to Debug It
- Method Security in Spring Security 7: @PreAuthorize, @PostAuthorize and the Proxy Traps
- CORS, CSRF and SameSite in Spring Boot 4: The Three Settings Everyone Gets Wrong
- OAuth2 Login with Google and GitHub in Spring Boot 4.1
- Password Hashing in Java: BCrypt vs Argon2 vs PBKDF2 with Spring Security 7
- Multi-Factor Authentication in Spring Security 7 with @EnableMultiFactorAuthentication
- Passkeys and WebAuthn with Spring Security 7: Passwordless Login That Actually Works
- Keycloak with Spring Boot 4.1: Roles, Resource Server and Admin API
Testing
- Testing Spring Boot 4 Without Containers: WireMock, MockWebServer and @MockitoBean
- RestTestClient in Spring Framework 7: Testing REST APIs End-to-End (vs MockMvcTester)
- @DataJpaTest in Spring Boot 4.1 with Testcontainers @ServiceConnection
- Testing Asynchronous Code with Awaitility (@Async, Kafka Listeners, Schedulers)
- ArchUnit for Spring Boot: Enforcing Layered Architecture as a Unit Test
Running in production
- Spring Boot Actuator in Production: Every Endpoint, Securing It, and Custom Health Indicators
- Structured Logging in Spring Boot 4: SLF4J Fluent API, MDC, and Custom Formatters
- A Practical Guide to Monitoring Spring Boot Microservices: Prometheus, Grafana, and Boot 4.1’s OpenTelemetry Starter
- Dockerizing Spring Boot 4: Layered Jars, Buildpacks, Distroless and Image Size Benchmarks
- Spring Boot Docker Compose Support: Real Containers for Local Development
- Deploying Spring Boot 4 on Kubernetes: Probes, Graceful Shutdown, Limits and JVM Ergonomics
- Why Your Spring Boot App Takes 8 Seconds to Start: A Bean-by-Bean Diagnosis
- JVM Flags for Spring Boot in Containers (JDK 25/27): The Production Cheat Sheet
- Java Flight Recorder and Mission Control: Profiling a Live Spring Boot App in 20 Minutes
- Debugging OutOfMemoryError: Heap Dumps, Eclipse MAT, and the Five Leak Patterns in Spring Apps
Architecture
- Hexagonal Architecture (Ports and Adapters) in Spring Boot 4
- CQRS in Spring Boot Without a Framework: Separate Read Models and Projections
- Modular Monolith vs Microservices in 2026: A Java Decision Framework
- Spring Modulith 2.1: Enforcing Module Boundaries Inside a Spring Boot Monolith
- Saga Pattern in Spring Boot: Orchestration vs Choreography with Kafka
- Transactional Outbox with the Spring Modulith Event Publication Registry
Upgrading and versions
- Spring Boot 3 to 4 Migration Guide: What Actually Breaks, Why It Breaks, and How to Fix It
- Spring Boot 3.x Is EOL. Don’t Stop at 4.0. Target 4.1 Instead.
- Automating javax → jakarta and Boot 3 → 4 Upgrades with OpenRewrite
- Spring Security 5 to 6 to 7 Migration: SecurityFilterChain, Lambda DSL, and the Silent Authorization Changes
- Jakarta EE 11 for Spring Developers: What Actually Matters
- Spring Boot 4.2 Preview: AMQP 1.0, Buildpack Image Cache and What to Test Now
Interview preparation
- Top 50 Spring Boot 4 Interview Questions and Answers (2026)
- Top 40 Spring MVC Interview Questions and Answers (2025)
Common interview questions
What is Spring Boot and why use it?
A framework layer on Spring that auto-configures the application, embeds a server and provides starters, so you can build a production-ready service with minimal setup.
What is the difference between Spring and Spring Boot?
Spring is the framework; Boot configures it for you. See Spring vs Spring Boot vs Spring MVC.
What does @SpringBootApplication do?
It enables component scanning, auto-configuration and marks the class as a configuration class.
What is a Spring Boot starter?
A dependency that bundles the libraries for one purpose, such as spring-boot-starter-webmvc for web apps.
How does auto-configuration work?
Boot checks the classpath and your beans and registers defaults for what it finds, backing off when you define your own bean. Write your own starter shows the mechanism.
Common mistakes
- Putting the main class in the default package. Component scanning starts in the main class’s package; keep controllers and services under it.
- Using field injection with
@Autowired. Use a constructor. - Putting business logic in the controller. Keep controllers thin; see project structure.
- Not pinning the Boot version to a supported line. Boot 3.x is end of life; see versions.
- Exposing internal errors. The default 400/404 bodies hide details; add a global handler.
FAQ
How long does it take to learn Spring Boot?
The tutorial above gets a first endpoint running in minutes; the next two weeks are beans, configuration, data access and tests.
Do I need to learn Spring before Spring Boot?
No. Learn Boot first and the Spring concepts under it as they appear.
Which Java version does Spring Boot 4 need?
Java 17 or newer; Java 21 or 25 are the sensible LTS choices. See Spring Boot versions.
Is Spring Boot good for microservices?
Yes; see the microservices project and Modular Monolith vs Microservices in 2026: A Java Decision Framework.
Further reading
- DemoApplication.java, Components.java, More.java
- Spring Boot annotations list
- Spring Boot project structure
- Spring vs Spring Boot vs Spring MVC
- Spring Boot microservices project
- 10 Spring Boot project ideas
- Spring Boot CRUD with MySQL
- Spring Boot versions
- Top 50 Spring Boot 4 interview questions
- Top 40 Java Collections interview questions
- Top 40 Java concurrency interview questions
- Top 50 Java Stream API coding interview questions
- Spring Boot reference documentation
No Comments yet!