Spring Boot Fundamentals

Spring Boot Internals and Features

Your browser needs to be JavaScript capable to view this video

Try reloading this page, or reviewing your browser settings

This segment explores some of Spring Boot’s key features, and how they work internally. We’ll also review the Auto configuration feature and how help to configure Spring apps.

Keywords

  • spring boot
  • auto-configuration

About this video

Author(s)
Felipe Gutierrez
First online
22 May 2021
DOI
https://doi.org/10.1007/978-1-4842-7066-0_8
Online ISBN
978-1-4842-7066-0
Publisher
Apress
Copyright information
© Felipe Gutierrez 2021

Video Transcript

Hello and welcome back. Let’s review some of the Spring Boot internals and some of its features. Remember that the Spring Boot is an opinionated runtime for the Spring Projects. This means that Spring Boot is going to use sensible defaults that are based on your classpath. The magic happens, actually, because there is a auto configuration that has been enabled by the app enabled auto configuration annotation. This means that this configuration can be easily overridden, either using the .properties file or .yaml files. Also, by the XML, if you have any Java config or any annotations.

The @enableautoconfiguration annotation normally is going to read the spring autoconfigure meta-inf spring factories. Again, we are going to review this very soon. We’re going to do actually a walkthrough. But what actually the spring factory contains? Well, it contains a list of classes that normally end with the auto configuration postfix. And normally it’s going to bring all the logic that is necessary to do its magic, in this case to do the auto configuration.

Normally, some of these classes are going to use these particular annotations. They add conditionalonclass, meaning that if you have a class, you need to do certain things, a certain logic. If you already have a conditional bean or you have a particular bean, you’re going to do something else. If you’ve already said certain kind of a property, so you override some properties, you’re going to do another kind of execution.

Also you have, if you haven’t declared any of the beans, is going to declare those, and so forth, right? So there are a lot of these kind of class that allows Spring Boot to do its magic and do the configuration. And again, normally it sets the default for the spring applications based on the spring beans. In other words, thanks to this auto configuration classes, this spring application on the spring context is going to set this spring beans.

Now let’s take a look into this diagram. So for example, if you have in your classpath the Spring Boot starter JDBC, what it’s going to do is it’s going to take a look into the datasource. Meaning that if you have these classes, it’s going to do or perform a certain kind of execution. And based on that, it’s going to create either the datasource, maybe some connection pool, or any other parameter that you require in order to connect to a database.

And for example, if you have the H2 database, the default provides that if you have this class, then the embedded database configuration is going to kick in, meaning that it’s going to set up everything that you need in order to use the data source, as H2 engine, right? And, of course, they’re going to show it could be either Tomcat or Carrot. Those are the defaults for this Spring Boot. So let’s take a look into their auto configuration. Let’s walk through to this so you understand what is actually happening behind the scenes.