00:00

Spring Boot Introduction

Last updated:

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 an open-source, Java-based framework designed to simplify the process of building standalone, production-ready applications. It is built on top of the Spring Framework and reduces the amount of manual configuration required.

Spring Boot can be used to develop a variety of applications, including:

  • REST APIs and Web Applications: Build web services and dynamic websites.
  • Microservices: Develop small, independent services that work together.
  • Batch Jobs and Scheduled Tasks: Process large amounts of data and automate tasks at scheduled times.
  • Message-Driven Applications: Process messages using messaging platforms such as Kafka or RabbitMQ.
  • Command-Line Tools: Create applications that run directly from a terminal.

2. Features of Spring Boot

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.

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:

pom.xml
<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.

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.

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.

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.

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.

3. Spring Boot: Simplifying Java Development

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. How Spring Boot Initializes an Application

When you start a Spring Boot application, the following steps typically occur:

  1. The main method calls SpringApplication.run(...) to launch the application.
  2. Spring Boot loads configuration from sources such as application.properties, YAML files, environment variables, and command-line arguments.
  3. Spring scans configured packages for eligible components annotated with @RestController, @Service, and other annotations, registering them as Spring beans.
  4. Spring Boot applies auto-configuration, conditionally configuring components such as web servers, database connections, and other services based on the available dependencies and application settings.
  5. Spring's dependency injection mechanism connects the beans and provides them with their required dependencies.
  6. For a typical web application, the embedded web server starts, allowing the application to accept HTTP requests.

5. 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.

FieldChoose
ProjectMaven
LanguageJava
Spring BootThe latest stable version (no SNAPSHOT or RC label)
Groupcom.javabytechie
Artifactgreeting
PackagingJar
Java17 or newer
DependenciesSpring 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.

6. Understanding the Project Structure

Project layout
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:

pom.xml
<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>

7. The Main Application Class

Every Spring Boot application has one class with a main method and the @SpringBootApplication annotation:

GreetingApplication.java
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.

8. Writing Your First REST Endpoint

Create a new class next to the main class. This controller answers HTTP requests with JSON:

GreetingController.java
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) {
    }
}
PartMeaning
@RestControllerThis class handles web requests and returns data, not HTML pages
@GetMapping("/hello")Run this method for GET requests to /hello
@RequestParamRead name from the URL, for example ?name=Asha
Returning a recordSpring Boot converts it to JSON automatically

9. Running the Application

Start the application from your IDE by running the main method, or from a terminal in the project folder:

Terminal
# macOS / Linux
./mvnw spring-boot:run

# Windows
mvnw.cmd spring-boot:run

After a few seconds, the log shows that the server is ready:

Console
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:

Terminal
curl "http://localhost:8080/hello?name=Asha"
Response
{
  "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:

Terminal
./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.

10. Configuring the Application

Change the defaults in src/main/resources/application.properties:

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:

GreetingController.java
@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:

Terminal
java -jar target/greeting-0.0.1-SNAPSHOT.jar --server.port=7070

11. 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.

12. 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.