-
DispatchServlet 분석SPRING/스프링 MVC 2021. 6. 6. 19:17
DispatchServlet은 아래와 같이 구성되어 있다.
MultipartResolver
- 파일 업로드 요청 처리에 필요한 인터페이스
LocaleResolver
- 클라이언트의 위치(Locale) 정보를 파악하는 인터페이스
ThemeResolver
- 애플리케이션에 설정된 테마를 파악하고 변경할 수 있는 인터페이스
HandlerMapping
- 요청을 처리할 핸들러를 찾는 인터페이스
- 기본적으로 아래 두개가 등록이 되어 있다.
- RequestMappingHandlerMapping : Annotation을 기반으로 Handler를 찾는다.
- BeanNameUrlHandlerMapping : Bean 이름을 기반으로 Handler를 찾는다.
HandlerAdapter
- HandlerMapping이 찾아낸 “핸들러”를 처리하는 인터페이스
HandlerExceptionResolver
- 요청 처리 중에 발생한 에러 처리하는 인터페이스
RequestToViewNameTranslator
- 핸들러에서 뷰 이름을 명시하지 않은 경우, 요청을 기반으로 뷰 이름을 판단하는 인터페이스
- hello.jsp로 매핑
@Controller public class siteController { @GetMapping("/hello") public void hello() { } }
ViewResolver
- 뷰 이름(string)에 해당하는 뷰를 찾아내는 인터페이스
@Controller public class HelloController { @Autowired HelloService helloService; @GetMapping("/hello") @ResponseBody public String hello() { return "Hello, " + helloService.getName(); } @GetMapping("/sample") public String sample() { return "sample"; } } @Configuration @ComponentScan public class WebConfig { @Bean public ViewResolver viewResolver() { // ViewResolver 설정 InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setPrefix("/WEB-INF/"); viewResolver.setSuffix(".jsp"); return viewResolver; } }
위와 같이 WebConfig에 ViewResolver를 설정하면 sample.jsp 호출을 full 경로를 쓰지 않고 할 수 있다.
'SPRING > 스프링 MVC' 카테고리의 다른 글
SPRING MVC 설정 관련 정리 (0) 2021.06.11 스프링 MVC -WEB.XML 제거 (0) 2021.06.10 스프링 MVC 연동 (0) 2021.06.06 스프링 IOC 컨테이너 연동 (0) 2021.06.05 서블릿 리스너와 필터 (0) 2021.06.05