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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
5分で問診!Composer セキュリティ健康診断
codmoninc
0
930
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
470
SlackアプリとLambdaの 連携を構築した話
pawn_4_s
1
110
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
380
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
260
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
550
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
120
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
330
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
200
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.7k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
For a Future-Friendly Web
brad_frost
183
10k
How to make the Groovebox
asonas
2
2.3k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
260
Navigating Weather and Climate Data
rabernat
0
470
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Statistics for Hackers
jakevdp
799
230k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
900
Building Adaptive Systems
keathley
44
3.2k
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