[Spring] Servlet으로 보는 WAS와 Web Architecture

민스킴·2023년 9월 12일
0

Spring

목록 보기
1/12

Web Application Server

김영한님의 스프링 기본편을 학습하는 도중, 스프링이 동적으로 클라이언트의 요청을 처리하는 과정이 궁금해서 찾아봤습니다.

Servlet Container



WAS 구조

Web Container == Servlet Container


웹 서버 구조

ServletContainer에서 Thread를 생성해서 사용할 Servlet이 이미 인스턴스로 존재하면 가져와서 사용하고, 없으면 초기화해서 service() 메소드를 실행합니다.
ServletContainer에서 HttpServletRequest, HttpServletResponse 인스턴스도 생성해서 전달해줍니다

Spring은 여기서 WebapplicationContext을 SpringContainer로 인스턴스를 생성해서 가지고 있다가, Servlet이 생성되고 Distpatcher-Servlet으로 SpringContainer안에 Spring Bean으로 생성되어있는 적절한 Controller를 호출하여 요청을 처리합니다.

Spring에서 Servlet의 Request 처리 순서

  1. 서버를 실행시켜 서블릿이 올라오는 동안에 init() 이 실행이 되고, 그 후에 dofilter 실행
  2. 컨트롤러에 들어가기 전 preHandler 실행
  3. 컨트롤러로 나와 postHandler, dfter Completion , doFilter 순으로 진행
  4. 서블릿 종료시 destroy 실행


이미지 출처 : https://stackoverflow.com/questions/4223564/servletconfig-vs-servletcontext

참고 블로그

ServletContext

Dispatcher-Servlet

Filter+AOP+Interceptor

profile
Boys, be ambitious!

0개의 댓글