SlideShare a Scribd company logo
Spring boot Under Da Hood
Spring boot Under Da Hood
The ApplicationContext
@Config
classes
ApplicationContext ctx = new AnnotationConfigApplicationContext(basePackage);
Fully
Configured
Application
Example
Bean
ctx.getBean(ExampleBean.class)
Xml
Files
ApplicationContext
What is Spring Boot doing for us?
SpringApplication.run(MyClass.class, args);
1. Creates an Spring applicationContext based on
1. the context information of the class passed in the runner (in this case,
MyClass.class)
2. Type of context (FE webappContext) based on classes in the classpath
2. Deduces the “main” class (for runnable jar packaging - > java –jar myApp.jar)
3. Enriches the applicationContext if AutoConfiguration annotation is present (more on this
in a moment)
4. Returns the applicationContext to the user / caller
@Component
@Service
@Bean
@Qualifier
@Controller
@RestController
@Repository
@PropertySource
@Configuration
@Import
@GetMapping, @PostMapping etc
All part of the Spring framework, NOT Spring Boot
SpringApplication class
public class SpringbootdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args);
}
}
@SpringBootApplication
@ComponentScan
@SpringBootApplication
component
component
component
component
Spring bean
@SpringBootConfiguration ~ @Configuration
@EnableAutoConfiguration
@Import(AutoConfigurationImportSelector.class)
@EnableAutoConfiguration
AutoConfigurationImportSelector implements ImportSelector
Interface (base Spring framework) to be implemented by types
that determine which @Configuration class(es) should be
imported
@AutoConfigurationPackage
Stores client side configuration package list for use by:
AutoConfigurationImportSelector
• Loads configuration classes using each META-INF/spring.factories it can find,
using SpringFactoriesLoader class
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveRestClientAutoConfiguration,
org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,
org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,
org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,
org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,
META-INF/spring.factories
JpaRepositoriesAutoConfiguration
@ConditionalOnBean({DataSource.class})
@ConditionalOnClass({JpaRepository.class})
@ConditionalOnMissingBean({JpaRepositoryFactoryBean.class, JpaRepositoryConfigExtension.class})
@ConditionalOnProperty(
prefix = "spring.data.jpa.repositories",
name = {"enabled"},
havingValue = "true",
matchIfMissing = true
)
• Loads if DataSource bean is present
• AND the JpaRepository class is on the classpath
• AND no custom JpaRepositoryFactoryBean is present
• AND property condition matches
Spring Backs out based on your own
Application context
Spring boot Under Da Hood
How is the embedded webserver (Tomcat)
started?
…Just another AutoConfig!
• If applicationContext type is SERVLET (Servlet class is on the
classpath),
EmbeddedWebServerFactoryCustomizerAutoConfiguration
is loaded
• If Tomcat class is on the classpath,
TomcatWebServerFactoryCustomizer is initialized, which
configures and starts Tomcat server with a DispatcherServlet that
delegates requests to the applicationContext (normal SpringWebMvc
behaviour)
How to build your own autoconfig!
• SomeLibrary – existing library that you want to support in SB
• SomeLibraryAutoConfig – contains conditionals and bean factories
• SomeLibraryStarter – just a POM that bundles as dependencies:
• SomeLibrary
• SomeLibraryAutoConfig
• Your Application – imports SomeLibraryStarter as a dependency
Artifact dependency tree
Your SB Application
SomeLibrary
Starter
SomeLibrary
AutoConfiguration
SomeLibrary
Depends on
Depends on
Depends on
Depends on
Spring factories
@Conditional configs
Just a pom
FlyWay, H2
Let’s build our own starter!
Summary –Spring Boot at its core
• Provide utility class to load application context
• Introduce autoconfig mechanism through @Conditional annotations
https://github.com/MichelSchudel/springbootunderdahood
Spring boot Under Da Hood

More Related Content

PPTX
ID連携のあるとき~、ないとき~ #エンプラ編
PPTX
Cryptography 101 for Java Developers - Devoxx 2019
PDF
Javaのログ出力: 道具と考え方
PPTX
今から始めるWebClient(JSUG勉強会 2020年その6 LT大会)
PDF
怖くないSpring Bootのオートコンフィグレーション
PPTX
KeycloakでAPI認可に入門する
PDF
Mavenの真実とウソ
ODP
Secure coding in C#
ID連携のあるとき~、ないとき~ #エンプラ編
Cryptography 101 for Java Developers - Devoxx 2019
Javaのログ出力: 道具と考え方
今から始めるWebClient(JSUG勉強会 2020年その6 LT大会)
怖くないSpring Bootのオートコンフィグレーション
KeycloakでAPI認可に入門する
Mavenの真実とウソ
Secure coding in C#

What's hot (20)

PPTX
フリーでできるWebセキュリティ(burp編)
PPTX
Tomcatの実装から学ぶクラスローダリーク #渋谷Java
PPTX
Java8勉強会
PDF
Form認証で学ぶSpring Security入門
PDF
インフラ野郎 Azureチーム at クラウド boost
PDF
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
PPTX
Spring boot Introduction
PDF
俺が考えた最強のID連携デザインパターン
PDF
Fido認証概要説明
PDF
ドメイン駆動設計 基本を理解する
PDF
Secure Spring Boot Microservices with Keycloak
PDF
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
PDF
Spring Bootをはじめる時にやるべき10のこと
PDF
Alfresco勉強会#26 Alfresco SDK + Eclipseで開発してみよう
PPTX
はじめてのElasticsearchクラスタ
PDF
Keycloakの最近のトピック
PDF
超実践 Cloud Spanner 設計講座
PPTX
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
PDF
プロトコルから見るID連携
PPTX
Spring Boot
フリーでできるWebセキュリティ(burp編)
Tomcatの実装から学ぶクラスローダリーク #渋谷Java
Java8勉強会
Form認証で学ぶSpring Security入門
インフラ野郎 Azureチーム at クラウド boost
Spring Data RESTを利用したAPIの設計と、作り直しまでの道のり
Spring boot Introduction
俺が考えた最強のID連携デザインパターン
Fido認証概要説明
ドメイン駆動設計 基本を理解する
Secure Spring Boot Microservices with Keycloak
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
Spring Bootをはじめる時にやるべき10のこと
Alfresco勉強会#26 Alfresco SDK + Eclipseで開発してみよう
はじめてのElasticsearchクラスタ
Keycloakの最近のトピック
超実践 Cloud Spanner 設計講座
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
プロトコルから見るID連携
Spring Boot
Ad

Similar to Spring boot Under Da Hood (20)

ODP
Different Types of Containers in Spring
PDF
Testing Web Apps with Spring Framework 3.2
PDF
quickguide-einnovator-2-spring4-dependency-injection-annotations
PPTX
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
PPTX
PDF
Testing Web Apps with Spring Framework 3.2
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example with test
PDF
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
PDF
Spring 3.1 in a Nutshell - JAX London 2011
PPTX
Spring framework
PPT
Spring Boot in Action
PDF
2-0. Spring ecosytem.pdf
PPT
Web Applications and Deployment
PPTX
Next stop: Spring 4
PDF
Spring 3.1 in a Nutshell
PDF
Spring 3.1 and MVC Testing Support
PPTX
Spring MVC 5 & Hibernate 5 Integration
PPTX
Java J2EE Interview Questions Part 2
PPTX
Java J2EE Interview Question Part 2
PPT
Introduction to Java Servlets and JSP (1).ppt
Different Types of Containers in Spring
Testing Web Apps with Spring Framework 3.2
quickguide-einnovator-2-spring4-dependency-injection-annotations
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Testing Web Apps with Spring Framework 3.2
Springboot2 postgresql-jpa-hibernate-crud-example with test
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring 3.1 in a Nutshell - JAX London 2011
Spring framework
Spring Boot in Action
2-0. Spring ecosytem.pdf
Web Applications and Deployment
Next stop: Spring 4
Spring 3.1 in a Nutshell
Spring 3.1 and MVC Testing Support
Spring MVC 5 & Hibernate 5 Integration
Java J2EE Interview Questions Part 2
Java J2EE Interview Question Part 2
Introduction to Java Servlets and JSP (1).ppt
Ad

More from Michel Schudel (16)

PPTX
java 21 unleashed: exciting new features since java 17!
PPTX
Testing an onion architecture - done right
PPTX
What makes a high performance team tick?
PPTX
Atonomy of-a-tls-handshake-mini-conferentie
PPTX
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
PPTX
Cryptography 101 for_java_developers, Fall 2019
PPTX
Cryptography 101 for Java Developers - JavaZone2019
PPTX
Micronaut brainbit
PPTX
Java n-plus-1-incl-demo-slides
PPTX
Cryptography 101 for Java developers
PPTX
Let's build a blockchain.... in 40 minutes!
PPTX
Cryptography 101 for Java developers
PPTX
Let's Build A Blockchain... in 40 minutes!
PPTX
What's new in Java 11
PPTX
Java 9 overview
PPTX
Test your microservices with REST-Assured
java 21 unleashed: exciting new features since java 17!
Testing an onion architecture - done right
What makes a high performance team tick?
Atonomy of-a-tls-handshake-mini-conferentie
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Cryptography 101 for_java_developers, Fall 2019
Cryptography 101 for Java Developers - JavaZone2019
Micronaut brainbit
Java n-plus-1-incl-demo-slides
Cryptography 101 for Java developers
Let's build a blockchain.... in 40 minutes!
Cryptography 101 for Java developers
Let's Build A Blockchain... in 40 minutes!
What's new in Java 11
Java 9 overview
Test your microservices with REST-Assured

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPT
Introduction Database Management System for Course Database
PDF
medical staffing services at VALiNTRY
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
ai tools demonstartion for schools and inter college
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Digital Strategies for Manufacturing Companies
PPTX
Essential Infomation Tech presentation.pptx
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
The Five Best AI Cover Tools in 2025.docx
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction Database Management System for Course Database
medical staffing services at VALiNTRY
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Softaken Excel to vCard Converter Software.pdf
Materi_Pemrograman_Komputer-Looping.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
Materi-Enum-and-Record-Data-Type (1).pptx
ai tools demonstartion for schools and inter college
Odoo POS Development Services by CandidRoot Solutions
Digital Strategies for Manufacturing Companies
Essential Infomation Tech presentation.pptx
ISO 45001 Occupational Health and Safety Management System
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Wondershare Filmora 15 Crack With Activation Key [2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

Spring boot Under Da Hood