3.DispatcherServlet
Spring MVC, as many other web frameworks, is designed around the front controller pattern where a central Servlet, the DispatcherServlet, provides a shared algorithm for request processing, while actual work is performed by configurable delegate components. This model is flexible and supports diverse workflows.
The
DispatcherServlet, as anyServlet, needs to be declared and mapped according to the Servlet specification by using Java configuration or inweb.xml.In turn, the
DispatcherServletuses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling, and more .
DispatcherServlet 이란 스프링이 구현한 서블릿 클래스로, Spring MVC에서 FrontContrller 패턴으로 구현된 프론트 컨트롤러이자, HTTP 요청 처리의 진입점
2. DispatcherServlet의 역할
기본적인 사용자의 요청 처리는 DispatcherServlet이 담당,
사용자가 요청한 세부 경로에 맞게 적합한 Controller or Handler를 찾아 전달하여 요청을 처리한 후 결과를 응답/반환하는 역할 수행
또한 이러한 처리는 SOLID 원칙 중 SRP 원칙에 의해 DispatcherServlet 혼자서 담당하지 않고,
각각의 역할을 세분화하여 구현된 다른 클래스들과 상호작용하면서 처리됨
Servlet 스택 기반 springframework에서 에서 web 요청과 관련된 처리는
org.springframework.web.servlet 패키지에서 담당함
3. DispatcherServlet 요약
DispatcherServlet은 Spring MVC 모듈에서 제공하는 클래스이자 개발자들이 편하게 사용할 수 있도록 이미 만들어져 있음
따라서 개발자는 해당 클래스 및 Spring MVC의 API를 잘 사용하면 됨
추가적인 세부 기능이 필요할 경우, 상속이나 구현과 같은 Java의 객체 지향 패러다임을 통해 개발자가 직접 커스터마이징할 수도 있음