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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Madhura Bhave
May 17, 2019
Programming
560
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Breaking the Magician's Code
Diving deeper into Spring Boot internals
Madhura Bhave
May 17, 2019
More Decks by Madhura Bhave
See All by Madhura Bhave
How to get productive with Spring Boot
mbhave
0
56
What's new in Spring boot 2.0 - Spring IO
mbhave
4
2.4k
A Sneak Peek into Spring Boot 2.0
mbhave
3
1.6k
Other Decks in Programming
See All in Programming
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
350
AIの中の人になってみる
htkym
0
140
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
240
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
260
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
5
1.8k
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
320
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
120
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
550
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.8k
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
170
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
260
Featured
See All Featured
The Language of Interfaces
destraynor
162
27k
Abbi's Birthday
coloredviolet
3
9.6k
Design in an AI World
tapps
1
290
The Spectacular Lies of Maps
axbom
PRO
1
950
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
180
New Earth Scene 8
popppiees
3
2.5k
A designer walks into a library…
pauljervisheath
211
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Faster Mobile Websites
deanohume
310
32k
How to Talk to Developers About Accessibility
jct
2
530
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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