Spring Boot Core Concepts Tutorial

Spring Boot is a Java framework built on top of Spring that simplifies application development. It eliminates boilerplate code with auto-configuration. Spring Boot comes with an embedded server, making applications production ready out of the box. It supports web apps, REST APIs, microservices, security and seamless cloud deployment.

In simple terms: Spring provides the building blocks; Spring Boot assembles common pieces so you can focus on your application.

What is Spring Boot?

Spring Boot is an opinionated framework built on top of the Spring Framework. It helps developers create production-ready Java applications quickly by choosing sensible defaults and reducing the amount of configuration they must write.

Opinionated does not mean that Spring Boot removes your choices. It means Spring Boot provides a good default first, while still allowing you to change the configuration when your application needs something different.

Why was Spring Boot created?

Before Spring Boot, starting a Spring application often meant configuring many separate pieces manually:

This setup could require hundreds of lines of configuration before the first business feature was written.

Traditional Spring vs Spring Boot
Traditional SpringConfigure server, context, beans, dependencies, and properties manually
Spring BootAdd starters, use defaults, and run the application
Ready applicationFocus on business features

Minimal Spring Boot application

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

With this class and the right starter dependency, Spring Boot can start the application context and an embedded web server. You can run it like a normal Java program, without separately installing and deploying a WAR file to Tomcat.

Key advantages

Advantage What it means
Embedded Tomcat The server can run inside your executable JAR.
Auto-configuration Spring Boot configures common components when their dependencies are present.
Starter dependencies One dependency brings a compatible group of libraries.
Less XML Java configuration, annotations, and properties replace most manual XML setup.
Production features Health checks, metrics, external configuration, and logging support are available.
Easy deployment Build one JAR and run it with java -jar.

Real-world analogy: opening a restaurant

Imagine opening a restaurant.

Restaurant analogy
Traditional SpringYou arrange tables, chairs, kitchen equipment, gas, electricity, menu, and chef separately
Spring BootThe restaurant infrastructure is ready; you focus on cooking the food

Spring Boot prepares the common infrastructure. You still decide what your application does, how its business rules work, and which features your users receive.

Spring vs Spring Boot

Spring is a large ecosystem for building Java applications. Traditionally, developers configured many objects and framework integrations by hand. Spring Boot adds conventions, starter dependencies, embedded servers, and automatic configuration to reduce that setup work.

What happens when a Boot app starts
main()Start the application
SpringApplicationCreates the context
Auto-configurationFinds useful defaults
Embedded serverServes the application

Minimal application

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

@SpringBootApplication combines component scanning, auto-configuration, and a configuration class. SpringApplication.run() creates the application context and starts the embedded server when web dependencies are present.

Key ideas

Auto-Configuration

Auto-configuration is Spring Boot's way of choosing common beans for you. Boot checks the libraries on the classpath, your configuration properties, and the beans you already defined. It creates sensible defaults only when they are needed.

How auto-configuration makes a decision
ClasspathIs Spring MVC present?
ConditionsIs a matching bean missing?
Default beanConfigure it automatically

For example, when the web starter is present, Boot can configure an embedded server, Spring MVC infrastructure, JSON support, and a dispatcher servlet. If you define your own bean, Boot usually backs away so your explicit choice wins.

Remember: Auto-configuration is a collection of conditional configuration classes that can be inspected, overridden, or disabled when necessary.

Including dependencies to activate auto-configuration

Auto-configuration is driven by the dependencies in your project. Adding a starter places the required libraries on the classpath, so Spring Boot can detect the feature and configure it.

<!-- Adds Spring MVC, Jackson, validation support, and embedded Tomcat -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Adds JPA, Hibernate, transactions, and repository support -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

After these dependencies are available, Boot checks their classes and creates the matching infrastructure. A dependency does not automatically create a useful application feature by itself; your controllers, entities, repositories, and properties still need to be provided.

Excluding an auto-configuration class

Sometimes a dependency is present but your application does not need the feature it normally activates. You can exclude the related auto-configuration class.

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

The same exclusion can be configured without changing the Java class:

# application.properties
spring.autoconfigure.exclude=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

This is useful for a service that includes a database-related library transitively but does not connect to a database. Exclude only what you understand; removing required auto-configuration can cause missing beans or startup errors.

Excluding an individual dependency

Dependency exclusion is different from auto-configuration exclusion. A dependency exclusion prevents a library from being downloaded or used, while an auto-configuration exclusion keeps the library but prevents Boot from creating its default beans.

<!-- Keep Spring MVC, but remove embedded Tomcat -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Replacing embedded Tomcat with Jetty

Spring Boot's web starter uses embedded Tomcat by default. To use Jetty instead, exclude the Tomcat starter and add the Jetty starter. Do not keep both servlet containers in the same application because the server configuration can become ambiguous.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<!-- Add the alternative embedded servlet container -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Changing the embedded servlet container
spring-boot-starter-webTomcat by default
Exclude TomcatRemove the default server
Add JettyRun the same MVC app on Jetty

Your controllers and REST endpoints usually do not change because Spring MVC sits above the servlet container. The main difference is the embedded server that receives HTTP requests and starts the application.

Useful auto-configuration controls

Requirement Approach Example
Add a feature Add a starter or library spring-boot-starter-data-jpa
Change a default value Set a property server.port=8081
Replace a default bean Define your own @Bean Custom ObjectMapper
Disable configuration Use exclude or spring.autoconfigure.exclude DataSourceAutoConfiguration
Change the web server Exclude Tomcat and add Jetty spring-boot-starter-jetty

Starters

A Spring Boot Starter is a carefully selected group of dependencies for one application capability. Instead of finding and adding every library separately, you add one starter and Spring Boot brings in the commonly required libraries.

How a starter helps create an application feature
Choose a capability
spring-boot-starter-web
Spring MVC + JSON + embedded server
Auto-configuration creates the web infrastructure

Example: adding the Web starter

To build REST APIs, add the Web starter to pom.xml:

spring-boot-starter-web