What is Spring Boot? Auto configurations In-Depth

You can use this guide to get an in-depth understanding of what Spring Boot is, how its AutoConfigurations work and what the difference with the Spring Framework is.

Introduction

It looks like everyone and their grandma are using Spring Boot to build projects. But very few can answer the question: “What is Spring Boot?”

The short answer:

Spring Boot’s website offers the following answer: “Spring Boot takes an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss.”

Wow, that doesn’t help at all, does it?

Luckily, there’s also a long answer:

The remainder of this article.

A quick caveat

I can give you a 99,99% guarantee, that you’d rather want to read the What is Spring Framework? article first, if…​:

  • …​you are completely new to Spring Boot (or Java).
  • …​you think ” Spring Framework, Spring Web MVC and Spring Boot are all the same”.
  • …​you think “Cut all this other crap, I just want to learn about Spring Boot!”.
  • (Especially if you think “cut all this other crap”).

Take the time to finish the previous article first, then come back here.

Furthermore, if you are looking for some simple copy & paste Spring Boot REST/microservice tutorials, I would advise you to go to spring boot 2 course, instead.

This article’s goals

  • To give you an in-depth understanding of Spring Boot and its AutoConfigurations.
  • To show you how Spring Boot automagically boots up a Tomcat server whenever you run a main() method.
  • To show you how Spring Boot’s properties magic works. You specify a couple of properties and suddenly have working database access.

Let’s start.

Spring Boot Basics: Conditionals

Before you become a Spring Boot guru, you need to understand just one very important concept: Spring Framework’s @Conditional annotation.

Parental Advice: Don’t skip this section, as it is the basis for everything that Spring Boot does. Also, I’ll make it as interesting as possible.

How to share ApplicationContextConfigurations?

Imagine you are working for ReallyBigCompany™ with a couple of teams working on different Spring projects or products. But you are not using Spring Boot, just plain Spring Framework.

Also imagine that at one point, one of your developers had a great idea to extract one common ApplicationContextConfiguration out of all projects, because she noticed that every company project uses a few of the same beans.

@Configuration
public class ReallyBigCompanySharedContextConfiguration { // (1)

    @Bean
    public ReallyBigCompanyProprietaryFlywayClone flywayClone() {
        return new ReallyBigCompanyProprietaryFlywayClone(); // (2)
    }

}
  1. This SharedContextConfiguration would live in its own project, eventually published as of its own .jar file that all your company’s Spring projects can import as a Maven/Gradle dependency.
  2. Imagine that ReallyBigCompany built a proprietary Flyway clone, i.e. something that initializes and manages databases. And as every project in your company uses a relational database, it makes sense to extract it to this shared configuration.

Your actual project ApplicationContextConfigurations would then do this:

@Configuration
@Import(ReallyBigCompanySharedConfiguration.class) // (1)
public class EarlyExitUnicornProjectContextConfiguration {

   // (2)
}
  1. Every company project from now on imports the SharedConfiguration, as it contains so many goodies (well, only the Flyway clone at the moment, but you get the point).
  2. You would specify your project-specific beans here, as normal.

Article Abode
Logo
Shopping cart