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
390
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
42
What's new in Spring boot 2.0 - Spring IO
mbhave
4
2.2k
A Sneak Peek into Spring Boot 2.0
mbhave
3
1.3k
Other Decks in Programming
See All in Programming
Node.js v22 で変わること
yosuke_furukawa
PRO
7
2.6k
코틀린으로 멀티플랫폼 만들기
pangmoo
0
150
2 週間で Twitter Bot を作ってみた
contour_gara
0
280
#phpcon_odawara オープン・クローズドなテストフィクスチャを求めて / open closed test fixtures
77web
3
230
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.7k
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
4k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.3k
Code Reviews
bkuhlmann
4
890
Snowflakeで眠ったデータを起こそう!
estie
0
110
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
120
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
730
Featured
See All Featured
Thoughts on Productivity
jonyablonski
58
3.8k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
YesSQL, Process and Tooling at Scale
rocio
164
13k
The Cult of Friendly URLs
andyhume
74
5.7k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
14
1.6k
A designer walks into a library…
pauljervisheath
200
23k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
How GitHub (no longer) Works
holman
304
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
19
1.7k
Unsuck your backbone
ammeep
663
57k
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