/spring-mvc-study

Spring MVC Study (learning DispatcherServlet initialization & service process)

Primary LanguageJava

Spring MVC Study

๐Ÿ“– Learning DispatcherServlet initialization & service process

Spring Version: 4.3.3
Build tool: Gradle

์Šคํ”„๋ง MVC Reference ๋ฒˆ์—ญ ์ •๋ณด

Study Database

DispatcherServlet ์˜ ๊ตฌ์กฐ
  • Servlet ์ƒ์† ๊ตฌ์กฐ

    • [Spring] DispatcherServlet : doDispatcher ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด web request ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ์ค‘์•™ ์ฒ˜๋ฆฌ ํด๋ž˜์Šค
    • [Spring] FrameworkServlet : ์„œ๋ธ”๋ฆฟ ์›น ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ  do* ๋ฉ”์„œ๋“œ๋ฅผ ๋‹ค์‹œ doService ๋ฉ”์„œ๋“œ๋กœ ๋ชจ์•„์ฃผ๋Š” ์ถ”์ƒํด๋ž˜์Šค
    • [Spring] HttpServletBean : init ๋ฉ”์„œ๋“œ๋ฅผ ์žฌ์ •์˜ํ•˜๋ฉฐ ์„ค์ • ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ์ถ”์ƒ ํด๋ž˜์Šค
    • [Servlet] HttpServlet : service ๋ฉ”์„œ๋“œ๋กœ์˜ ์š”์ฒญ์„ do* ๋ฉ”์„œ๋“œ๋กœ ์ „๋‹ฌํ•˜๋Š” ์ถ”์ƒํด๋ž˜์Šค
    • [Servlet] GenericServlet : ServletConfig ์˜ ์„ค์ •์„ ๋‹ด๋‹นํ•˜๋Š” ์ถ”์ƒํด๋ž˜์Šค
    • [Servlet] Servlet(interface) : Servlet ์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค (init, service, destroy)
  • ApplicationContext ๊ตฌ์„ฑ ๋ฐ ์ดˆ๊ธฐํ™”

    • ApplicationContext ์ƒ์„ฑ: FrameworkServlet#createWebApplicationContext()
    • BeanFactory ์ƒ์„ฑ: AbstractRefreshableApplicationContext#refreshBeanFactory()
    • BeanDefinition ๋กœ๋”ฉ: AnnotationConfigWebApplicationContext:loadBeanDefinitions()
    • BeanPostProcessor ๋“ฑ๋ก: PostProcessorRegistrationDelegate:registerBeanPostProcessors()
    • SingletonBean (์ „์ฒ˜๋ฆฌ)๋ฏธ๋ฆฌ ๋“ฑ๋ก: DefaultListableBeanFactory:preInstantiateSingletons()

ApplicationContext ๋ฅผ ์ƒ์„ฑ(์ดˆ๊ธฐํ™”)ํ•˜๋Š” ์ฒซ ๋‹จ๊ณ„๋Š” DispatcherServlet ์˜ ๋ถ€๋ชจ ํด๋ž˜์Šค์ธ HttpServletBean ์˜ init() ๋ฉ”์„œ๋“œ์ด๋‹ค. ์ด ํด๋ž˜์Šค๋Š” Servlet Spec ์— ๋”ฐ๋ผ init ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š”๋ฐ ์ด๋•Œ FrameworkServlet ํด๋ž˜์Šค์˜ initServletBean() ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ์ด ๋ถ€๋ถ„์„ ๋ณด๋ฉด ApplicationContext ์˜ ์‹œ์ž‘์ง€์ ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

๐ŸŒฑ DispatcherServlet ์˜ ์ดˆ๊ธฐํ™” ๊ณผ์ •

๐ŸŒฟ BeanFactory ์˜ ์ดˆ๊ธฐํ™” ๊ณผ์ •

๐ŸŒฒ ์›น ์š”์ฒญ์˜ ์ฒ˜๋ฆฌ ๊ณผ์ •

ํด๋ž˜์Šค ๋ณ„ ์„ค์ • ๋ฐ์ดํ„ฐ ์ •๋ณด

DispatcherServlet
BeanFactory
RequestMappingHandlerMapping
RequestMappingHandlerAdapter

๐ŸšŒ ์Šคํ„ฐ๋”” ์ง„ํ–‰ ํ˜„ํ™ฉ

์‚ฌ์ „ ๋ชจ์ž„

์ฒซ๋ฒˆ์งธ ๋ชจ์ž„: Spring MVC ๋ฅผ ์™œ ๊ณต๋ถ€ํ• ๊นŒ

๋‘๋ฒˆ์งธ ๋ชจ์ž„: Spring MVC ๋Š” ๋ฌด์—‡์ผ๊นŒ

์„ธ๋ฒˆ์งธ ๋ชจ์ž„: doDispatch ๋ฉ”์„œ๋“œ์˜ ์—ญํ• ์€

๋„ค๋ฒˆ์งธ ๋ชจ์ž„: RequestMappingHandlerMapping ์˜ ์—ญํ• ์€

๋‹ค์„ฏ๋ฒˆ์งธ ๋ชจ์ž„: RequestMappingHandlerAdapter ์˜ ์—ญํ• ์€

์—ฌ์„ฏ๋ฒˆ์งธ ๋ชจ์ž„: ArgumentResolver ์˜ ์—ญํ• ์€

์ผ๊ณฑ๋ฒˆ์งธ ๋ชจ์ž„: ArgumentResolver ์‚ดํŽด๋ณด๊ธฐ

์—ฌ๋Ÿ๋ฒˆ์งธ ๋ชจ์ž„: ReturnValueHandler ์‚ดํŽด๋ณด๊ธฐ

์•„ํ™‰๋ฒˆ ๋ชจ์ž„: ViewResolver ์‚ดํŽด๋ณด๊ธฐ

์—ด๋ฒˆ์งธ ๋ชจ์ž„: View ์‚ดํŽด๋ณด๊ธฐ

๋งˆ์ง€๋ง‰ ๋ชจ์ž„: Spring MVC ๋Š” ๋ฌด์—‡์ผ๊นŒ?

๐Ÿค” ์Šคํ„ฐ๋”” ๋งˆ์ง€๋ง‰ ์ •๋ฆฌ(๋‚ด๊ฐ€ ์ƒ๊ฐํ•˜๋Š” Spring MVC)

CHH, HCH, HKH, HSM, KDH, KHG, KIK, KYS, YHJ