Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
450
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
43
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.4k
Other Decks in Programming
See All in Programming
Ethereum_.pdf
nekomatu
0
460
CSC509 Lecture 11
javiergs
PRO
0
180
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
最新TCAキャッチアップ
0si43
0
140
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
920
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
The Pragmatic Product Professional
lauravandoore
31
6.3k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Speed Design
sergeychernyshev
25
620
Visualization
eitanlees
145
15k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Six Lessons from altMBA
skipperchong
27
3.5k
Fireside Chat
paigeccino
34
3k
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