Example usage for org.springframework.web.servlet DispatcherServlet DispatcherServlet

List of usage examples for org.springframework.web.servlet DispatcherServlet DispatcherServlet

Introduction

In this page you can find the example usage for org.springframework.web.servlet DispatcherServlet DispatcherServlet.

Prototype

public DispatcherServlet(WebApplicationContext webApplicationContext) 

Source Link

Document

Create a new DispatcherServlet with the given web application context.

Usage

From source file:edu.chalmers.dat076.moviefinder.initializer.ProjectWebApplicationInitializer.java

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

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(applicationContext));
    dispatcher.setLoadOnStartup(1);/*from w  w w.jav  a 2  s  .co  m*/
    dispatcher.addMapping("/");
}

From source file:com.miko.s4netty.config.WebInitializer.java

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

    logger.debug("WebInitializer onStartup");

    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("WEB-INF/spring/dispatcher-servlet.xml");

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);/*from   w w w  . ja va  2s .  c om*/

}

From source file:eu.agilejava.spring4.config.ApplicationInitializer.java

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

    WebApplicationContext context = createWebAppContext();
    servletContext.addListener(new ContextLoaderListener(context));

    ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher",
            new DispatcherServlet(context));
    registration.setLoadOnStartup(1);/* ww  w  .j av a2 s.c  o  m*/
    registration.addMapping("/api/*");

}

From source file:com.rakesh.rp3599.config.WebAppInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppContext.class);

    /** Dispatcher Servlet **/
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);/*www  . j  av  a2 s .c  om*/
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    /** Dispatcher Types Enum **/
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    /** UTF-8 Filter **/
    FilterRegistration.Dynamic characterEncoding = container.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    /** Context Listener **/
    container.addListener(new ContextLoaderListener(rootContext));

}

From source file:com.digitgroup.fullstackroad.spring.config.web.WebAppInitializer.java

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

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

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

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);//from www .  j a  va 2s  .com
    dispatcher.addMapping("/");

}

From source file:org.uoiu.platform.web.DefaultWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    //    appContext.register(AppConfig.class);
    appContext.getEnvironment().setActiveProfiles("webapp");
    servletContext.addListener(new ContextLoaderListener(appContext));

    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(mvcContext));
    dispatcher.setLoadOnStartup(1);//from   w  ww  . j  a  v a  2s. c  o  m
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter",
            characterEncodingFilter());
    encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}

From source file:com.dominion.salud.nomenclator.configuration.NOMENCLATORInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.scan("com.dominion.salud.nomenclator.configuration");
    ctx.setServletContext(servletContext);
    ctx.refresh();/*from w w w  .j  ava  2  s  .c  o m*/

    logger.info("     Registrando servlets de configuracion");
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(ctx));
    dispatcher.setInitParameter("contextClass", ctx.getClass().getName());
    dispatcher.setLoadOnStartup(1);
    logger.info("          Agregando mapping: /");
    dispatcher.addMapping("/");
    logger.info("          Agregando mapping: /controller/*");
    dispatcher.addMapping("/controller/*");
    logger.info("          Agregando mapping: /services/*");
    dispatcher.addMapping("/services/*");
    servletContext.addListener(new ContextLoaderListener(ctx));
    logger.info("     Servlets de configuracion registrados correctamente");

    // Configuracion general
    logger.info("     Iniciando la configuracion del modulo");
    NOMENCLATORConstantes._HOME = StringUtils.endsWith(servletContext.getRealPath("/"), File.separator)
            ? servletContext.getRealPath("/")
            : servletContext.getRealPath("/") + File.separator;
    NOMENCLATORConstantes._TEMP = NOMENCLATORConstantes._HOME + "WEB-INF" + File.separator + "temp"
            + File.separator;
    NOMENCLATORConstantes._VERSION = ResourceBundle.getBundle("version").getString("version");
    NOMENCLATORConstantes._LOGS = NOMENCLATORConstantes._HOME + "WEB-INF" + File.separator + "classes"
            + File.separator + "logs";
    NOMENCLATORConstantes._CONTEXT_NAME = servletContext.getServletContextName();
    NOMENCLATORConstantes._CONTEXT_PATH = servletContext.getContextPath();
    NOMENCLATORConstantes._CONTEXT_SERVER = servletContext.getServerInfo();
    NOMENCLATORConstantes._ENABLE_TECHNICAL_INFORMATION = StringUtils.isNotBlank(
            ResourceBundle.getBundle("application").getString("nomenclator.enable.technical.information"))
                    ? Boolean.parseBoolean(ResourceBundle.getBundle("application")
                            .getString("nomenclator.enable.technical.information"))
                    : false;
    PropertyConfigurator.configureAndWatch("log4j");

    logger.info("          Configuracion general del sistema");
    logger.info("               nomenclator.home: " + NOMENCLATORConstantes._HOME);
    logger.info("               nomenclator.temp: " + NOMENCLATORConstantes._TEMP);
    logger.info("               nomenclator.version: " + NOMENCLATORConstantes._VERSION);
    logger.info("               nomenclator.logs: " + NOMENCLATORConstantes._LOGS);
    logger.info("               nomenclator.context.name: " + NOMENCLATORConstantes._CONTEXT_NAME);
    logger.info("               nomenclator.context.path: " + NOMENCLATORConstantes._CONTEXT_PATH);
    logger.info("               nomenclator.context.server: " + NOMENCLATORConstantes._CONTEXT_SERVER);
    logger.info("          Parametrizacion del sistema");
    logger.info("               nomenclator.enable.technical.information: "
            + NOMENCLATORConstantes._ENABLE_TECHNICAL_INFORMATION);
    logger.info("     Modulo configurado correctamente");
    logger.info("MODULO INICIADO CORRECTAMENTE");
}

From source file:org.jboss.arquillian.spring.testsuite.beans.web.EmployeeWebInitializer.java

/**
 * {@inheritDoc}/*from w ww  .  j  a  va  2  s  . co  m*/
 */
public void onStartup(ServletContext servletContext) throws ServletException {

    // creates the web app context
    AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    webContext.register(WebAppConfig.class);

    // registers context load listener
    servletContext.addListener(new ContextLoaderListener(new AnnotationConfigWebApplicationContext()));

    // adds a dispatch servlet, the servlet will be configured from root web app context
    ServletRegistration.Dynamic servletConfig = servletContext.addServlet("employee",
            new DispatcherServlet(webContext));
    servletConfig.setLoadOnStartup(1);
    servletConfig.addMapping("*.htm");
}

From source file:com.github.sshw.config.RootApplicationConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);//from w  ww .  j  ava2s . com
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    security.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:com.rockagen.gnext.main.BootStrap.java

protected void addServlet(final ServletContext ctx) {
    DispatcherServlet ds = new DispatcherServlet(rootContext);
    // Spring mvc
    ctx.addServlet("spring-mvc", ds).addMapping("/");

    StatViewServlet druid = new StatViewServlet();

    // Druid view
    ctx.addServlet("druid", druid).addMapping("/druid/*");

}