DispatcherServlet 이란?

DispatcherServlet 이란?

HTTP Request handlers/controllers 를 관리하는 전달자(dispatcher).
Web Request 수행, 쉬운 매핑기능, 예외처리기능등을 제공을 위해
등록된 핸들러로 전달한다.

web.xml 에 등록해서 사용된다.

   dispatcher
   
     org.springframework.web.servlet.DispatcherServlet
   
   
     contextConfigLocation
     /WEB-INF/spring/dispatcher-config.xml
   
   1
 

 
   dispatcher
   /
 

물론 Servlet3.0+ 이후버전에서는 dispatcher-sevlet.xml, web.xml모두
Class 를 통한 설정이 가능해졌다.

public class MyWebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) {
      // Create the 'root' Spring application context
      AnnotationConfigWebApplicationContext rootContext =
        new AnnotationConfigWebApplicationContext();
      rootContext.register(AppConfig.class);

      // Manage the lifecycle of the root application context
      container.addListener(new ContextLoaderListener(rootContext));

      // Create the dispatcher servlet's Spring application context
      AnnotationConfigWebApplicationContext dispatcherContext =
        new AnnotationConfigWebApplicationContext();
      dispatcherContext.register(DispatcherConfig.class);

      // Register and map the dispatcher servlet
      ServletRegistration.Dynamic dispatcher =
        container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
      dispatcher.setLoadOnStartup(1);
      dispatcher.addMapping("/");
    }

 }


References


댓글

가장 많이 본 글