-
Spring MVC Component의 동작구조(그림주의)스터디 노트 2023. 10. 23. 13:25
안녕하세요. 오늘은 웹 개발의 기본 중의 기본인 Spring MVC 컴포넌트의 동작 구조에 대해 간략하게 설명을 해볼까 합니다.
우선 스프링 프레임워크는 제공되는 컴포넌트들이 매우 긴밀하게 연관이 되어 있습니다.
이들 컴포넌트는 HandlerMapping, HandlerAdapter, ModelAndView, ViewResolver, DispatchServlet이 그것입니다.
다음은 해당 컴포넌트들의 동작 구조에 대한 설명입니다.
참고로 첨부된 그림은 제 손으로 그린 그림이다보니, 육안으로 구별이 많이 힘드실 수도 있습니다..
1. 클라이언트에서 전송된 모든 HTTP 요청 메시지는 가장 먼저 DispatcherServelet이 받아 처리합니다.
2. DispatcherServlet은 요청 메시지의 요청 라인과 헤더들을 파악한 후 어떤 컨트롤러 클래스의 어떤 메서드로 해당 요청을 전달할지 HandlerMapping 컴포넌트의 메서드를 통해 확인한다.
3. DispatcherServlet은 사용자 요청을 처리할 수 있는 컨트롤러 클래스에 HTTP 요청 메시지를 전달하기 위해 전달 역할을 하는 HandlerAdaptr에 해당 요청을 전달합니다.
4. HandlerAdapter는 컨트롤러에게 전달받은 클라이언트의 요청을 전달합니다.
5. 컨트롤러 클래스는 개발된 비즈니스 로직 서비스 레이어로 해당 처리를 위임합니다. 비즈니스 로직 처리가 완료된 이후 결과값이 다시 컨트롤러 클래스에 전달되면 이를 어떤 뷰로 전달할지 결정하죠.
6. HandlerAdapter는 처리할 뷰와 뷰에 매핑할 데이터를 ModelAndView 객체에 포함해 DispatcherServlet에 전달합니다.
7. DispatcherServlet은 처리할 뷰 정보를 ViewResolver에 확인하게 됩니다.
8. DispatcherServlet은 View에 데이터를 전달하고, View는 데이터를 HTML이나 XML 등 적합한 포맷으로 변환한 뒤 이를 DispatcherSerlvet에 다시 전달합니다.
9. 최종적으로 반환된 데이터를 클라이언트에게 전달합니다.이렇게 전반적인 Spring MVC Component들의 동작 구조에 대해 살펴보았습니다.
여기서 실제 개발자가 컨트롤할 수 있는 부분은 Controller부터 Biz Logic부분까지 이지요.
사실 Component 설정도 직접 컨트롤 할 수 있기는 하지만요 ㅎ
'스터디 노트' 카테고리의 다른 글
제네릭의 변성, 공변, 반공변 등등의 개념들 (0) 2023.10.30 REST API의 개념과 설계 방법 (0) 2023.10.24 HTTP Status Code (0) 2023.10.20 스프링 빈, 자바 빈, DTO, VO의 차이점과 불변객체(Immutable Object) (0) 2023.10.20 Transaction이 뭐길래? (1) 2023.10.19