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 - Diving deeper in...
Search
Phil Webb
February 28, 2017
Technology
2.1k
2
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
Presented @DevNexus '17
Phil Webb
February 28, 2017
More Decks by Phil Webb
See All by Phil Webb
Spring Boot for the Java EE Developer
philwebb
1
450
Behind the OSS curtain: How we manage Spring
philwebb
1
340
Keeping It Clean
philwebb
9
1k
Other Decks in Technology
See All in Technology
知らん間に、回ってる
ming_ayami
0
720
ガバナンスの「ちょうどいい落とし所」を探れ!開発スピードを妨げない運用判断の勘所 / SRE NEXT 2026
genda
1
250
人を動かすのは時間ではなく、納得感 〜新任EMが入社3ヶ月、組織を2回変えた話〜
kakehashi
PRO
3
270
Amplify Gen2でbackend.tsにCDKを定義する/しない事によるCDKの挙動の違いとユースケース
smt7174
1
410
穢れた技術選定について
watany
17
5.5k
個人開発で育てる「大規模設計の苗床」 - AI時代の1人開発から始める業務への知識接続 / The Seedbed for Large-Scale Design - From AI-Era Solo Projects to Professional Knowledge
bitkey
PRO
1
280
End-to-Endで考える信頼性 —LINEアプリにおけるクライアント開発×SRE連携の実践
maruloop
4
4.6k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.4k
Genie Ontologyは銀の弾丸かを考える / Is Genie Ontology a Silver Bullet?
nttcom
0
400
公式ドキュメントの歩き方etc
coco_se
1
120
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
300
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
510
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Mobile First: as difficult as doing things right
swwweet
225
10k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
280
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
Ethics towards AI in product and experience design
skipperchong
2
330
The untapped power of vector embeddings
frankvandijk
2
1.8k
The Curse of the Amulet
leimatthew05
2
13k
Are puppies a ranking factor?
jonoalderson
1
3.7k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
290
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
Transcript
Breaking the Magician's Code Diving deeper into Spring Boot internals
@phillip_webb @madhurabhave23
None
DEMO start.spring.io
DEMO Starting from scratch
Embedded Servlet Container Tomcat WAR ServletContainerInitializer AbstractAnnotationConfigDispatcherServletInitializer WebApplicationContext Dispatcher Servlet
Embedded Servlet Container WebApplicationContext Embedded EmbeddedServletContainerFactory EmbeddedServletContainer getEmbeddedServletContainer( ServletContextInitializer... initializers);
EmbeddedServletContainer start() stop() getPort()
DEMO Back to the CODE
Servlets WebApplicationContext Embedded Servlet Filter ServletContextInitializer ServletRegistrationBean FilterRegistrationBean
Servlets WebApplicationContext Embedded 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
DEMO Back to the CODE
Spring Boot Code •ConditionalOnAClass -> ConditionalOnClass • MagicApplication -> SpringBootApplication
• EnableMagicAutoConfiguration -> EnableAutoConfiguration • EnableMagicProperties -> EnableConfigurationProperties • *Configuration -> *AutoConfiguration
Summary • There’s no such thing as magic • Follow
the breadcrumbs • Annotations • Import Selectors • Spring Factories • Conditions • Use the source!
Thanks! Questions? @madhurabhave23 @phillip_webb speakerdeck.com/philwebb https://github.com/mbhave/non-magic-demo