2011년 12월 7일 수요일

Spring Web.xml and Annotation Configurer


 <servlet>
     <servlet-name>dispatcher</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

   <servlet-mapping>
     <servlet-name>dispatcher</servlet-name>
     <url-pattern>/*</url-pattern>
   </servlet-mapping>

---------------------------------------------------------------------------------

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import
       org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;



public class WebAppInitializer implements WebApplicationInitializer {


       @Override
public void onStartup(ServletContext servletContext) throws ServletException {




        AnnotationConfigWebApplicationContext dispatcherContext =
                                                          new AnnotationConfigWebApplicationContext();
dispatcherContext.register(DispatcherConfig.class);

ServletRegistration.Dynamic dispatcher =
servletContext.addServlet("dispatcher",
                                                 new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");

       }

}

댓글 없음:

댓글 쓰기