Spring Boot Introduction
Spring Boot is the most popular way to build Java applications today, from small web services to large enterprise systems. It takes care of the setup work that used to slow Java projects down, so you can go from an empty folder to a running web application in a few minutes.
This beginner-friendly introduction explains what Spring Boot is, how it relates to the Spring Framework, which problems it solves and how it works. It then walks you through building, running and configuring your first application.
1. What Is Spring Boot?
Spring Boot is a free, open-source Java framework for building applications on top of the Spring Framework. It gives you sensible default settings, ready-made dependency bundles and a built-in web server, so most applications need very little setup to start working.
Think of the Spring Framework as a big, well-equipped kitchen: it has every tool you could want, but you must choose and arrange everything yourself before you can cook. Spring Boot is the same kitchen, already set up for the most common recipes. You can start cooking straight away, and you can still rearrange anything you like.
With Spring Boot you can build:
- REST APIs and web applications
- Microservices
- Batch jobs and scheduled tasks
- Applications that process messages from Kafka or RabbitMQ
- Command-line tools
2. Spring Framework vs Spring Boot
Spring Boot does not replace Spring; it is built on top of it. Everything you learn about Spring still applies. Spring Boot simply removes much of the manual work:
| Spring Framework | Spring Boot | |
|---|---|---|
| What it is | The core framework: dependency injection, web, data access and more | A layer on top of Spring that configures it for you |
| Configuration | You set up most beans yourself, in Java or XML | Sensible defaults, applied automatically |
| Dependencies | You choose each library and a compatible version | Starters bring tested sets of libraries |
| Web server | You install Tomcat separately and deploy a WAR file | A server is built in; you run a single JAR file |
| Production features | You add health checks and metrics yourself | Ready-made with Spring Boot Actuator |
| Getting started | Slower, with more decisions up front | Minutes, with a generated project |
For a deeper comparison, including the same application built both ways, see Spring Boot vs Spring Framework.
3. Why Was Spring Boot Created?
Before Spring Boot, starting a Spring project meant a lot of repetitive setup:
- Long configuration files. Even a small web application needed many lines of XML or Java configuration to wire up the database, transactions and the web layer.
- Version conflicts. You had to find versions of Spring, Hibernate, Jackson and other libraries that worked together, and one mismatch could cause confusing errors.
- Separate server setup. Applications were packaged as WAR files and deployed to an application server that had to be installed and configured separately.
- Repeated boilerplate. Every new project copied the same setup from the previous one.
Spring Boot, first released in 2014, solved these problems with convention over configuration: if you follow common conventions, the framework handles the details, and you only write configuration when you want something different.
4. Key Features of Spring Boot
4.1 Auto-configuration
Spring Boot looks at the libraries in your project and configures them automatically. Add a database driver, and it sets up a connection pool. Add the web starter, and it configures a web server and JSON support. If you define your own version of something, Spring Boot uses yours instead.
4.2 Starters
A starter is a single dependency that brings in everything needed for one kind of work, in versions that are tested together. One line gives you a complete web stack:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Notice that there is no version number. Spring Boot manages compatible versions for you.
4.3 Embedded web server
Spring Boot includes a web server (Tomcat by default; Jetty is an alternative) inside your application. You run the application like any Java program, and the server starts with it. There is nothing to install separately.
4.4 Externalized configuration
Settings such as the port, database URL or feature switches live outside your code, in application.properties, environment variables or command-line arguments. The same build can then run in development, testing and production with different settings.
4.5 Production-ready features
Spring Boot Actuator adds health checks, metrics and information endpoints, so you can monitor your application in production without writing that code yourself.
4.6 Developer tools
Spring Boot DevTools restarts the application automatically when you change code during development, which saves you from stopping and starting it by hand.
5. How Spring Boot Works
When you start a Spring Boot application, these steps happen in a few seconds:
- The
mainmethod callsSpringApplication.run(...). - Spring Boot reads your configuration from
application.propertiesand other sources. - It scans your packages for classes marked with annotations such as
@RestControllerand@Service, and creates objects (called beans) for them. - It runs auto-configuration, creating beans for the libraries it finds, such as a web server or a database connection.
- It connects the beans together through dependency injection.
- It starts the embedded web server, and your application is ready to accept requests.
6. What You Need Before You Start
| Tool | Notes |
|---|---|
| Java Development Kit (JDK) 17 or newer | Current Spring Boot versions require at least Java 17; Java 21 or newer is a good choice |
| A build tool | Maven or Gradle; every generated project includes a wrapper, so you do not need to install either |
| An IDE | IntelliJ IDEA, Eclipse with Spring Tools, or VS Code with the Java and Spring extensions |
| Basic Java knowledge | Classes, interfaces, annotations and collections |
Check your Java version in a terminal:
java -version
7. Creating Your First Spring Boot Application
The easiest way to create a project is Spring Initializr, a free online project generator at start.spring.io. Most IDEs offer the same generator built in.
| Field | Choose |
|---|---|
| Project | Maven |
| Language | Java |
| Spring Boot | The latest stable version (no SNAPSHOT or RC label) |
| Group | com.javabytechie |
| Artifact | greeting |
| Packaging | Jar |
| Java | 17 or newer |
| Dependencies | Spring Web |
Click Generate, unzip the downloaded file, and open the folder in your IDE. The IDE downloads the dependencies automatically; this takes a minute the first time.
8. Understanding the Project Structure
greeting/
├── mvnw, mvnw.cmd Maven wrapper scripts (no Maven install needed)
├── pom.xml Dependencies and build settings
└── src/
├── main/
│ ├── java/com/javabytechie/greeting/
│ │ └── GreetingApplication.java The main class
│ └── resources/
│ ├── application.properties Configuration
│ ├── static/ Images, CSS, JavaScript
│ └── templates/ HTML templates (if used)
└── test/
└── java/com/javabytechie/greeting/
└── GreetingApplicationTests.java
The generated pom.xml inherits from spring-boot-starter-parent, which supplies tested library versions and build defaults:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version> <!-- the version you chose on start.spring.io -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
9. The Main Application Class
Every Spring Boot application has one class with a main method and the @SpringBootApplication annotation:
package com.javabytechie.greeting;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GreetingApplication {
public static void main(String[] args) {
SpringApplication.run(GreetingApplication.class, args);
}
}
@SpringBootApplication switches on three things at once: configuration support, auto-configuration, and scanning of this package and its sub-packages for your classes. That is why the main class should sit in the top-level package, above all your other code. For a closer look, see Spring Boot Annotations.
10. Writing Your First REST Endpoint
Create a new class next to the main class. This controller answers HTTP requests with JSON:
package com.javabytechie.greeting;
import java.time.LocalDateTime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
@GetMapping("/hello")
public Greeting hello(@RequestParam(defaultValue = "World") String name) {
return new Greeting("Hello, " + name + "!", LocalDateTime.now());
}
public record Greeting(String message, LocalDateTime time) {
}
}
| Part | Meaning |
|---|---|
@RestController | This class handles web requests and returns data, not HTML pages |
@GetMapping("/hello") | Run this method for GET requests to /hello |
@RequestParam | Read name from the URL, for example ?name=Asha |
Returning a record | Spring Boot converts it to JSON automatically |
11. Running the Application
Start the application from your IDE by running the main method, or from a terminal in the project folder:
# macOS / Linux
./mvnw spring-boot:run
# Windows
mvnw.cmd spring-boot:run
After a few seconds, the log shows that the server is ready:
Tomcat started on port 8080 (http) with context path '/'
Started GreetingApplication in 1.8 seconds (process running for 2.1)
Open http://localhost:8080/hello?name=Asha in your browser, or call it from a terminal:
curl "http://localhost:8080/hello?name=Asha"
{
"message": "Hello, Asha!",
"time": "2026-10-04T10:30:15.482"
}
Congratulations: that is a working web service, with no XML, no server installation and no manual wiring.
11.1 Building a runnable JAR
To run the application on a server, package it as one self-contained JAR file:
./mvnw clean package
java -jar target/greeting-0.0.1-SNAPSHOT.jar
The JAR contains your code, all libraries and the web server, so any machine with Java can run it.
12. Configuring the Application
Change the defaults in src/main/resources/application.properties:
# Run on port 9090 instead of 8080
server.port=9090
# A name for the application, shown in logs and monitoring tools
spring.application.name=greeting-service
# Your own settings
greeting.default-name=Friend
Read your own settings in code with @Value:
@RestController
public class GreetingController {
private final String defaultName;
public GreetingController(@Value("${greeting.default-name}") String defaultName) {
this.defaultName = defaultName;
}
@GetMapping("/hello")
public Greeting hello(@RequestParam(required = false) String name) {
String who = (name == null || name.isBlank()) ? defaultName : name;
return new Greeting("Hello, " + who + "!", LocalDateTime.now());
}
}
Any property can also be overridden when starting the application, without changing the file:
java -jar target/greeting-0.0.1-SNAPSHOT.jar --server.port=7070
13. Common Spring Boot Starters
| Starter | Adds |
|---|---|
spring-boot-starter-web | REST APIs and web applications, with Tomcat and JSON support |
spring-boot-starter-data-jpa | Database access with JPA and Hibernate |
spring-boot-starter-validation | Validation of input data with annotations |
spring-boot-starter-security | Login, authentication and authorization |
spring-boot-starter-actuator | Health checks, metrics and monitoring endpoints |
spring-boot-starter-thymeleaf | Server-side HTML pages |
spring-boot-starter-cache | Caching method results |
spring-boot-starter-test | JUnit 5, Mockito, AssertJ and Spring test support |
You can add starters at any time: put the dependency in pom.xml, reload the project, and Spring Boot configures the new feature on the next start.
14. Advantages and Limitations
14.1 Advantages
- Fast to start: a working project in minutes, with almost no setup.
- Less code: auto-configuration removes most boilerplate.
- Fewer version problems: starters bring libraries that are tested together.
- Easy to run anywhere: one JAR file with a built-in server, ideal for containers and the cloud.
- Production-ready: health checks, metrics and externalized configuration out of the box.
- Huge ecosystem: integrations for almost every database, message broker and cloud service.
- Strong community: plenty of documentation, examples and answers online.
14.2 Limitations
- “Magic” can confuse beginners: when something is configured automatically, it is not always obvious where it came from.
- Larger applications: starters may bring libraries you never use, which makes the JAR bigger.
- Startup time and memory: a typical application uses more memory and starts more slowly than a plain Java program, although native images can help.
- Learning curve: understanding the Spring concepts underneath still takes time.
15. What to Learn Next
Once your first application runs, these tutorials build on it step by step:
| Topic | What you will learn |
|---|---|
| Spring Boot Annotations | The annotations you will use every day |
| Spring Boot Validation | Checking request data with annotations |
| Exception Handling | Returning clear error responses |
| Spring Data JPA | Saving and reading data from a database |
| Caching | Making slow operations fast |
| Async Processing | Running work in the background |
| Scheduler | Running tasks automatically on a schedule |
| Actuator | Monitoring your application in production |
16. Summary
Spring Boot builds on the Spring Framework and removes most of the setup work: auto-configuration provides sensible defaults, starters bring compatible libraries, and an embedded server lets you run everything as a single JAR. In this tutorial, you created a project with Spring Initializr, explored its structure, wrote a REST endpoint, ran it, and changed its configuration. From here, add features one starter at a time, and dive into the tutorials above as your application grows.
Frequently Asked Questions (FAQ)
Q1. Do I need to learn the Spring Framework before Spring Boot?
No, you can start with Spring Boot directly. Most developers today learn Spring through Spring Boot, because it lets you build something working right away.
As you progress, learn the core Spring ideas underneath, because Spring Boot uses them everywhere:
- Beans and the application context.
- Dependency injection: how objects receive what they need.
- Annotations such as
@Component,@Serviceand@Autowired.
Knowing these makes it much easier to understand what Spring Boot does automatically, and to fix problems when something does not work as expected.
Q2. Is Spring Boot free to use?
Yes. Spring Boot is open source under the Apache License 2.0. You can use it in personal, commercial and closed-source projects at no cost.
The free community releases receive updates and security fixes for a limited time after each version. Companies that need longer support for older versions can buy commercial support, but most projects simply upgrade to newer free versions.
Q3. Which Java version do I need?
Current Spring Boot versions (3.x and later) require Java 17 or newer. The older 2.x line worked with Java 8 and 11, but it no longer receives free updates.
For new projects, choose a long-term support (LTS) Java release such as Java 21. LTS versions receive updates for years, which makes them safer for production.
Q4. Should I choose Maven or Gradle?
Both work equally well with Spring Boot, and Spring Initializr can generate either one.
| Maven | Gradle | |
|---|---|---|
| Build file | pom.xml (XML) | build.gradle or build.gradle.kts (code) |
| Style | Fixed structure, very predictable | More flexible, often faster builds |
| Learning | Easier for beginners; most tutorials use it | Slightly steeper |
If you are just starting, choose Maven, since most examples, including the ones on this site, use it. If your team already uses Gradle, use that.
Q5. What does “opinionated” mean for Spring Boot?
It means Spring Boot makes sensible choices for you by default, based on what most applications need. For example:
- The web starter uses Tomcat as the server.
- JSON is handled with Jackson.
- Logging uses Logback.
- The server listens on port 8080.
These are only defaults, not rules. You can change any of them with a property, a dependency change, or your own configuration. The idea is: start fast with good choices, and override what you need.
Q6. What if I do not like one of Spring Boot’s defaults?
You can change almost any default, usually in one of three ways:
- Set a property in
application.properties, such asserver.port=9090. Most defaults have a matching property. - Define your own bean. When you create a bean of the same type, Spring Boot’s automatic one steps aside.
- Swap a dependency, for example excluding Tomcat and adding Jetty instead.
@Configuration
public class JsonConfig {
// Your own ObjectMapper replaces the one Spring Boot would create
@Bean
public ObjectMapper objectMapper() {
return JsonMapper.builder()
.findAndAddModules()
.build();
}
}
Q7. Can Spring Boot be used for applications that are not websites?
Yes. If you leave out the web starter, no web server starts, and the application simply runs its code. Use a CommandLineRunner for code that should run at startup:
@SpringBootApplication
public class ReportApplication implements CommandLineRunner {
private final ReportService reportService;
public ReportApplication(ReportService reportService) {
this.reportService = reportService;
}
public static void main(String[] args) {
SpringApplication.run(ReportApplication.class, args);
}
@Override
public void run(String... args) {
reportService.generateMonthlyReport(); // runs once, then the app exits
}
}
Spring Boot is also widely used for batch jobs, scheduled tasks and applications that process messages from queues.
Q8. Can I still deploy a Spring Boot application as a WAR file to an external Tomcat?
Yes, although a runnable JAR is simpler and more common. To build a WAR, change the packaging and extend SpringBootServletInitializer:
<packaging>war</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
@SpringBootApplication
public class GreetingApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(GreetingApplication.class, args);
}
}
Use this only when your company requires an existing application server. For new deployments, especially containers and cloud platforms, a JAR is easier.
Q9. I get “Port 8080 was already in use”. How do I fix it?
Another program, often a previous run of your own application, is already using port 8080. You have three options:
- Stop the other program. Check your IDE for an application that is still running.
- Find what is using the port:
# macOS / Linux
lsof -i :8080
# Windows
netstat -ano | findstr :8080
- Use a different port for your application:
server.port=8081
Setting server.port=0 picks a random free port, which is handy for tests.
Q10. Is Spring Boot only for microservices?
No. Spring Boot became famous with microservices because it makes small, independent services easy to build and run. It works just as well for:
- Monoliths: one larger application containing many features.
- Modular monoliths: one application split into clear internal modules.
- Internal tools, batch jobs and back-office systems.
Many teams start with a single well-structured Spring Boot application and only split it into microservices when there is a clear need.
Q11. Why does my Spring Boot application start slowly or use a lot of memory?
At startup, Spring Boot scans classes, creates beans and runs auto-configuration, which takes time and memory. Common ways to improve it:
- Remove starters you do not use. Each one brings more auto-configuration.
- Enable lazy initialization during development with
spring.main.lazy-initialization=true, so beans are created only when needed. - Use a newer Java version, which usually starts faster and uses memory more efficiently.
- Build a native image with GraalVM for very fast startup and low memory use, at the cost of a longer build.
./mvnw -Pnative native:compile
Q12. What does spring-boot-starter-parent do?
It is the parent of your pom.xml, and it gives your project three things:
- Dependency versions: hundreds of libraries with versions that are tested together, which is why starters need no version number.
- Sensible build settings, such as the Java version and UTF-8 encoding.
- Plugin setup for building the runnable JAR.
If your project must use another parent, import the spring-boot-dependencies BOM in <dependencyManagement> instead to get the same version management.
Q13. Should I use application.properties or application.yml?
Both do exactly the same job; the choice is about style:
# application.properties
server.port=9090
spring.application.name=greeting-service
# application.yml
server:
port: 9090
spring:
application:
name: greeting-service
Properties files are flat and simple. YAML groups related settings and suits long configurations, but its indentation must be exact. Pick one per project and stick to it.
Q14. What is Spring Boot DevTools, and should I use it in production?
DevTools speeds up development. It restarts your application automatically when you recompile code, and turns off template caching so page changes show immediately. Add it as an optional dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
Never use it in production. DevTools switches itself off automatically when the application runs from a packaged JAR with java -jar, but marking it optional also keeps it out of the final build.
Q15. How do Spring Boot versions work, and how do I upgrade?
Version numbers follow the pattern major.minor.patch, for example 3.5.2:
| Change | Example | Effort to upgrade |
|---|---|---|
| Patch | 3.5.1 → 3.5.2 | Bug and security fixes; usually just change the number |
| Minor | 3.4 → 3.5 | New features; small changes may be needed |
| Major | 2.x → 3.x | Bigger changes, such as a new minimum Java version |
New minor versions come out about twice a year. Upgrade regularly, one minor version at a time, read the release notes, and run your tests. Adding the spring-boot-properties-migrator dependency temporarily reports renamed or removed properties at startup.
Q16. Which IDE is best for Spring Boot?
Any modern Java IDE works. Popular choices:
- IntelliJ IDEA: the Community edition is free; the paid Ultimate edition adds extra Spring support.
- Eclipse with Spring Tools: free, with Spring-specific features.
- Visual Studio Code: free and lightweight, with the Java and Spring Boot extension packs.
All of them can create projects through Spring Initializr and run the main class with one click. Use whichever you are most comfortable with.
Q17. Can I use Spring Boot with Kotlin instead of Java?
Yes. Spring Boot fully supports Kotlin, and Spring Initializr can generate a Kotlin project. The same controller looks like this:
@RestController
class GreetingController {
@GetMapping("/hello")
fun hello(@RequestParam(defaultValue = "World") name: String) =
mapOf("message" to "Hello, $name!")
}
Groovy is also supported. Java remains the most common choice, with the most examples and answers available online.
Q18. How do I run my Spring Boot application in Docker?
Spring Boot can build a container image for you, with no Dockerfile needed, as long as Docker is running on your machine:
./mvnw spring-boot:build-image
docker run -p 8080:8080 greeting:0.0.1-SNAPSHOT
If you prefer to write your own Dockerfile, a minimal one copies the JAR into a Java runtime image:
FROM eclipse-temurin:21-jre
COPY target/greeting-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
Q19. What is the difference between Spring Boot and Spring MVC?
- Spring MVC is the part of the Spring Framework that handles web requests: controllers, request mapping and views.
- Spring Boot is not a web framework itself. It sets up and runs Spring applications, including Spring MVC.
When you add spring-boot-starter-web, you are using Spring MVC to write controllers, while Spring Boot configures it, adds JSON support and starts Tomcat. So you usually use them together rather than choosing between them.
Q20. What should I build as my first Spring Boot project?
Pick something small that touches the main building blocks, and grow it step by step:
- A to-do list API: REST endpoints to create, list, update and delete tasks.
- Add a database with Spring Data JPA, using the built-in H2 database at first.
- Add validation, so a task cannot have an empty title.
- Add exception handling, returning a clear 404 for unknown tasks.
- Write tests for the service and the controller.
- Add Actuator and package the app as a JAR or Docker image.
Each step matches one of the tutorials in the What to Learn Next section.