DispatcherSerlvet의 기본 전략
# Default implementation classes for DispatcherServlet's strategy interfaces.
# Used as fallback when no matching beans are found in the DispatcherServlet context.
# Not meant to be customized by application developers.
org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver
org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping,\
org.springframework.web.servlet.function.support.RouterFunctionMapping
org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter,\
org.springframework.web.servlet.function.support.HandlerFunctionAdapter
org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver,\
org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,\
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver
org.springframework.web.servlet.FlashMapManager=org.springframework.web.servlet.support.SessionFlashMapManager
MultipartResolver
LocaleResolver
ThemeResolver
Theme이라는 Key 값을 뷰에 전달하고 뷰가 Key 값에 해당하는 적절한 리소스(ex) css) 읽어와 테마를 그에 맞게 렌더링함
HandlerMapping
HandlerAdapter
HandlerExceptionResolver
@ExceptionHandler를 사용해 정의
RequestToViewNameTranslator
@Controller
public class HelloController {
@Autowired
HelloService helloService;
@GetMapping("/hello")
@ResponseBody
public String hello() {
return "Hello, " + helloService.getName();
}
@GetMapping("/sample")
public void sample(){
}
}
이런 경우에도 RequestToViewNameTranslator가 요청을 보고 sample이라는 뷰가 있을 것이라고 추측하고 뷰를 찾아주고 리턴한다.
ViewResolver
FlashMapManager
post 요청을 처리하고 데이터를 저장한 다음 get 요청으로 redirect를 하게 되는 데 그 이유는 화면을 refresh 했을 때 form submition이 또 발생하기 때문이다. 그래서 같은 데이터를 또 보내오지 않도록(중복 submition) 방지하기 위한 패턴이다. 그리고 get 요청으로 redirect를 했을 때 화면에서 뭔가 보여줘야 할 필요가 있을 수 있다. 그러면 RequestParameter나 PathVariable로 주지 않고도 (RedirectAttributes : redirect:/events/id=200, redirect:/events?id=200) 데이터를 전송할 수 있게끔 해주는 방법이 FlashMap이다.
DispatcherServlet.class
@Nullable
private MultipartResolver multipartResolver;
/** LocaleResolver used by this servlet. */
@Nullable
private LocaleResolver localeResolver;
/** ThemeResolver used by this servlet. */
@Nullable
private ThemeResolver themeResolver;
/** List of HandlerMappings used by this servlet. */
@Nullable
private List<HandlerMapping> handlerMappings;
/** List of HandlerAdapters used by this servlet. */
@Nullable
private List<HandlerAdapter> handlerAdapters;
/** List of HandlerExceptionResolvers used by this servlet. */
@Nullable
private List<HandlerExceptionResolver> handlerExceptionResolvers;
/** RequestToViewNameTranslator used by this servlet. */
@Nullable
private RequestToViewNameTranslator viewNameTranslator;
/** FlashMapManager used by this servlet. */
@Nullable
private FlashMapManager flashMapManager;
/** List of ViewResolvers used by this servlet. */
@Nullable
private List<ViewResolver> viewResolvers;
또한 HandlerMapping, HandlerAdapter, HandlerExceptionResolvers는 List<> 형태로 Collection이다. 여러 개의 빈을 순회하면서 요청을 처리할 수 있는지 판단한다.
참고