๐Ÿฅž BE
home

Spring MVC Deep Dive with CODE

Date
2024/08/21
Category
Web
Tag
Spring
Detail

Spring MVC Processing Sequence

1.
ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ย Dispatcher Servlet์— ์ „๋‹ฌ
2.
์š”์ฒญํ•œ url์— ๋งž๋Š”ย controllerย ๊ฒ€์ƒ‰ํ•˜์—ฌย Handler Mapping์— ์ „๋‹ฌ
3.
HandlerMapping์—์„œ ํ•ด๋‹นย controller์— ์ฒ˜๋ฆฌ ์š”์ฒญ
4.
controller์—์„œ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผย Handler Adapter์—์„œ ModelAndView ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌย Dispatcher Servlet์— ์ „๋‹ฌ
5.
Dispatcher Servlet์—์„œ ์ „๋‹ฌ๋ฐ›์€ย ModelAndView ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜์—ฌ ๋งคํ•‘๋˜๋Š” View๋ฅผ ๊ฒ€์ƒ‰
6.
viewResolver์—์„œ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผย view์— ์ „๋‹ฌ
7.
์ฒ˜๋ฆฌ๊ฒฐ๊ณผ๊ฐ€ ํฌํ•จ๋œย view๋ฅผย Dispatcher Servlet์— ์ „๋‹ฌ
8.
Dispatcher Servlet์—์„œ ์ตœ์ข… ์‘๋‹ต ๊ฒฐ๊ณผ๋ฅผ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐ˜ํ™˜

Dispatcher Servlet์˜ ๋™์ž‘ ์›๋ฆฌ

โ€ข
์šฐ์„  ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์œผ๋กœ servlet์ด ํ˜ธ์ถœ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ดย doService()ย ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋จ
โ€ข
doService()์˜ ์ฝ”๋“œ๋Š” ๋งจ ์•„๋ž˜์—์„œย doDispatch()ย ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋จ โ†’ ์ด์ œ ์‹ค์ œ๋กœ dispatch๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ณผ์ •์ด ์ง„ํ–‰๋จ

1. ํ•ธ๋“ค๋Ÿฌ ์กฐํšŒ, ํ•ธ๋“ค๋Ÿฌ ์–ด๋Œ‘ํ„ฐ ์กฐํšŒ

โ€ข
doDispatch()์—์„œ๋Š” ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ํ•ด๋‹นํ•˜๋Š”ย ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์กฐํšŒํ•˜๊ณ (getHandler()),ํ•ด๋‹น ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๋ฐ›๊ธฐ ์œ„ํ•œ ์–ด๋Œ‘ํ„ฐ๋ฅผ ์กฐํšŒ(getHandlerAdapter())
โ€ข
์œ„ ๊ณผ์ •์—์„œ 2, 3, 4 ๋‹จ๊ณ„๋ฅผ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ์ค€๋น„

2. ์œ„์—์„œ ์ฐพ์€ ํ•ธ๋“ค๋Ÿฌ ์–ด๋Œ‘ํ„ฐ์˜ย handle()ย ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ

โ€ข
์ด๋ฅผ ํ†ตํ•ดย ModelAndView๋ฅผ ๋ฐ˜ํ™˜
โ€ข
๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜์—์„œย processDispatchResult()ย ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ
โ€ข
2, 3, 4๋ฒˆ ๋‹จ๊ณ„ ์‹คํ–‰

3. ๋ทฐ ๋ Œ๋”๋ง ํ˜ธ์ถœ

โ€ข
processDispatchResult()ย ๋ฉ”์„œ๋“œ๋Š” ์•ˆ์—์„œย render()ย ๋ฉ”์„œ๋“œ๋ฅผ ๋˜ ๋‹ค์‹œ ํ˜ธ์ถœ
โ€ข
5, 6, 7, 8 ๋‹จ๊ณ„๋ฅผ ์œ„ํ•œ ์ค€๋น„

4. ๋ทฐ ๋ Œ๋”๋ง

โ€ข
render()ย ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ๋Š” ๋ทฐ ๋ฆฌ์กธ๋ฒ„(viewResolver)๋ฅผ ํ†ตํ•ด view๋ฅผ ์ฐพ๊ณ , ํ•ด๋‹น view๋ฅผ ๋ฐ˜ํ™˜๋ฐ›์Œ
โ€ข
๋งˆ์ง€๋ง‰์œผ๋กœ ๋ทฐ๋ฅผ ์‹ค์ œ๋กœ ๋ Œ๋”๋ง โ†’ ์ „๋‹ฌ
โ€ข
5, 6, 7, 8 ๋‹จ๊ณ„ ์‹คํ–‰