HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🤩
개발
/
Spring
Spring
/
⚽
Spring MVC Request Lifecycle
⚽

Spring MVC Request Lifecycle

notion image
notion image

Filter

  • request나 response에 대해 필터링 작업을 수행함
  • DispatcherServlet에 들어가기 전인 Web Application 단에서 실행됨

DispatcherServlet

  • 들어오는 모든 Request를 우선적으로 받아 처리해주는 Servlet임(Dispatcher = 배치 담당자. Request를 어느 컨트롤러로 매핑시킬 것인지 배치 하는 역할을 함)
  • HandlerMapping에게 Request에 대해 매핑할 Controller 검색을 요청
  • HandlerMapping 으로부터 Controller 정보를 반환 받아 해당 Controller와 매핑시킴

HandlerMapping

  • DispatcherServlet으로부터 검색을 요청받은 Controller를 찾아 정보를 리턴

HandlerInterceptor

  • 어떤 request에 대해 특정 기능을 적용하려 할 때 유용함. Intercepter는 HandlerInterceptor를 구현해야함
    • preHandle(): Before the actual handler is run
    • postHandle() : After the handler is run
    • afterCompletion() : After the complete request has finished()
  • 주로 세션, 쿠키, 권한 인증 로직에 많이 사용됨

Controller

  • request에 대해 어떤 로직(Service)로 처리할 것인지 결정, 그에 맞는 Service를 호출
  • Service Bean을 스프링 컨테이너로부터 주입 받아야 함

Service

  • 데이터 처리 및 가공을 위한 비즈니스 로직을 수행함

Repository

  • DB에 접근하는 객체로, DAO(Data Access Object)라고 부름
  • 데이터 CRUD를 할 수 있게 해줌

ViewResolver

  • Controller에서 리턴한 View의 이름을 DispatcherServlet 으로부터 넘겨 받고, 해당 View를 View에게 전달(렌더링 하라고)