$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Breaking the Magician's Code
Search
Madhura Bhave
May 17, 2019
Programming
0
540
Breaking the Magician's Code
Diving deeper into Spring Boot internals
Madhura Bhave
May 17, 2019
Tweet
Share
More Decks by Madhura Bhave
See All by Madhura Bhave
How to get productive with Spring Boot
mbhave
0
54
What's new in Spring boot 2.0 - Spring IO
mbhave
4
2.3k
A Sneak Peek into Spring Boot 2.0
mbhave
3
1.5k
Other Decks in Programming
See All in Programming
アーキテクチャと考える迷子にならない開発者テスト
irof
9
3.4k
Reactive Thinking with Signals and the new Resource API
manfredsteyer
PRO
0
140
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
1
190
Herb to ReActionView: A New Foundation for the View Layer @ San Francisco Ruby Conference 2025
marcoroth
0
230
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
560
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
260
目的で駆動する、AI時代のアーキテクチャ設計 / purpose-driven-architecture
minodriven
11
3.7k
Microservices rules: What good looks like
cer
PRO
0
250
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
190
Media Capture and Streams: W3C仕様と現場での知見
nowaki28
0
110
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
370
Atomics APIを知る / Understanding Atomics API
ssssota
1
230
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
4.9k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
65
Code Reviewing Like a Champion
maltzj
527
40k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Language of Interfaces
destraynor
162
25k
Docker and Python
trallard
46
3.7k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Automating Front-end Workflow
addyosmani
1371
200k
Transcript
Madhura Bhave @madhurabhave23 Breaking the Magician’s Code
DEMO start.spring.io
None
DEMO Starting from scratch
Embedded Servlet Container Tomcat WAR ServletContainerInitializer AbstractAnnotationConfigDispatcherServletInitializer WebApplicationContext Dispatcher Servlet
Embedded Servlet Container ServletWebServerApplicationContext ServletWebServerFactory WebServer getWebServer( ServletContextInitializer... initializers); WebServer
start() stop() getPort()
DEMO Back to the CODE
Servlets ServletWebServerApplicationContext Servlet Filter ServletContextInitializer ServletRegistrationBean FilterRegistrationBean
Servlets ServletWebServerApplicationContext Servlet DispatcherServlet @RequestMapping(“/foo”) @RequestMapping(“/bar”)
DEMO Back to the CODE
Component scanning • @Componentscan • base Packages • base Package
Classes • (default)
Component Scanning com.example.demo.core.* com.example.demo.domain.* com.example.demo.Application com.example.demo.config.*
Component Scanning example demo com config core domain
Component Scanning example demo com config core domain .Application
Component Scanning example demo com config core domain .Application
Component Scanning example demo com config core domain .Application
Component Scanning example demo com config core domain .Application
DEMO Back to the CODE
Meta-Annotations • Most Spring Annotations can be used as meta-annotations
• Use in your own code • Used extensively in the framework: •@RestController •@GetMapping
Meta-Annotations • @AliasFor for advanced mappings: @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan public
@interface SpringBootApplication { @AliasFor(annotation = EnableAutoConfiguration.class, attribute = "exclude") Class<?>[] exclude() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackages") String[] scanBasePackages() default {};
DEMO Back to the CODE
Advanced Imports •@Import(Regular.class) •ImportSelector • Return String[] •ImportBeanDefinitionRegistrar • Direct
registration
Spring Factories • Dirt simple way to discover implementations •
Similar to Java Service Loader • Simple properties file •/META-INF/spring.factories
DEMO Back to the CODE
Conditions • @Conditional annotation • Condition interface public interface Condition
{ boolean matches( ConditionContext context, AnnotatedTypeMetadata metadata); }
Conditions • Spring Framework @Profile • Spring Boot (Bean,Class,Property) •
Ordered so fastest run first
Spring Boot Code •ConditionalOnAClass -> ConditionalOnClass •MagicApplication -> SpringBootApplication •EnableMagicAutoConfiguration
-> EnableAutoConfiguration •*Configuration -> *AutoConfiguration
Summary • There’s no such thing as magic • Follow
the breadcrumbs • Annotations • Import Selectors • Spring Factories • Conditions • Use the source!
Madhura Bhave @madhurabhave23 Thanks! https://github.com/mbhave/non-magic-demo