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:com.mycompany.spring2explore.config.WebAppInitializer.java

@Override
public void onStartup(ServletContext cs) {

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(SpringRootConfig.class);
    // Manage the lifecycle of the root application context
    cs.addListener(new ContextLoaderListener(rootContext));

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

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = cs.addServlet("dispatcher",
            new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);//from   w  ww  .  j  a v  a  2 s.  c  om
    dispatcher.addMapping("/");
}

From source file:$.SpringAppInitializer.java

@Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        WebApplicationContext context = getContext();
        servletContext.addListener(new ContextLoaderListener(context));

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
                new DispatcherServlet(context));

        dispatcher.setLoadOnStartup(1);// w  w  w .ja  v  a  2 s .  c o  m
        dispatcher.addMapping(MAPPING_URL);
    }

From source file:org.bitcoinrt.atmosphere.config.BitcointWebAppInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
    webAppContext.register(WebConfig.class);

    final DispatcherServlet dispatcherServlet = new DispatcherServlet(webAppContext);

    @SuppressWarnings("serial")
    MeteorServlet meteorServlet = new MeteorServlet() {
        @Override/*from  w w  w .  j a va2 s . c om*/
        public void init(ServletConfig sc) throws ServletException {
            super.init(sc);

            // MeteorServlet only support init parameters but in Java config it's easier
            // to register instances. So we re-register the default Atmosphere handler.

            BroadcasterFactory.getDefault().remove("/*");
            framework.addAtmosphereHandler("/*", new ReflectorServletProcessor(dispatcherServlet));
            framework.initAtmosphereHandler(sc);
        }
    };

    servletContext.addServlet("meteor", meteorServlet).addMapping("/");
}

From source file:com.spawnin.battlecat.webapp.servletcontext.BattlecatWebApplicationInitializer.java

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

    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.setConfigLocation("com.spawnin.battlecat.core.config");

    ServletRegistration.Dynamic registration = servletContext.addServlet("battlecat",
            new DispatcherServlet(appContext));
    registration.setLoadOnStartup(1);/* w ww .  ja  v a 2 s .c  o m*/
    registration.addMapping("/");

}

From source file:com.gailo22.atmosphere.config.AtmosphereWebAppInitializer.java

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

    final AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
    webAppContext.register(WebConfig.class);

    final DispatcherServlet dispatcherServlet = new DispatcherServlet(webAppContext);

    @SuppressWarnings("serial")
    final MeteorServlet meteorServlet = new MeteorServlet() {
        @Override/* ww  w  . j a v  a 2  s  .c  o  m*/
        public void init(final ServletConfig sc) throws ServletException {
            super.init(sc);

            // MeteorServlet only support init parameters but in Java config it's easier
            // to register instances. So we re-register the default Atmosphere handler.

            BroadcasterFactory.getDefault().remove("/*");
            this.framework.addAtmosphereHandler("/*", new ReflectorServletProcessor(dispatcherServlet));
            this.framework.initAtmosphereHandler(sc);
        }
    };

    servletContext.addServlet("meteor", meteorServlet).addMapping("/");
}

From source file:org.synchronoss.cloud.nio.multipart.example.utils.WebAppInitializer.java

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

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("org.synchronoss.cloud.nio.multipart.example.config");
    context.setServletContext(servletContext);
    Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
    dynamic.setAsyncSupported(true);/*  w  w  w  .  j a v  a  2  s  . c  om*/
    dynamic.addMapping("/");
    dynamic.setLoadOnStartup(1);

}

From source file:com.test.config.BackendConsoleWebConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext();
    webCtx.register(BackendConsoleMVCConfig.class);
    webCtx.register(BackendConsoleConfig.class);

    servletContext.addListener(new ContextLoaderListener(webCtx));

    /* Spring Delegating Dispatcher Servlet */
    Servlet dispatcherServlet = new DispatcherServlet(webCtx);
    ServletRegistration.Dynamic dispatcherServletReg = servletContext.addServlet("dispatcherServlet",
            dispatcherServlet);/* w w w .j av a  2s .  co  m*/
    dispatcherServletReg.setLoadOnStartup(1);
    dispatcherServletReg.setInitParameter("contextConfigLocation", "");
    dispatcherServletReg.addMapping("/");

    /* Spring Security Delegating Filter */
    FilterRegistration springSecurityFilterChainReg = servletContext.addFilter("springSecurityFilterChain",
            DelegatingFilterProxy.class);
    springSecurityFilterChainReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.ASYNC), false,
            dispatcherServletReg.getName());
}

From source file:com.olegchir.fadeok.init.AppInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {
    System.out.println("Initializing Application for " + servletContext.getServerInfo());

    //Create webapp context
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.setConfigLocation(CONFIG_LOCATION);

    servletContext.addListener(new ContextLoaderListener(applicationContext));
    //        servletContext.addListener(new CompleteAutoloadTilesListener());

    // Add the servlet mapping manually and make it initialize automatically
    DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet);

    servlet.addMapping("/");
    servlet.setAsyncSupported(true);/*w  ww  .  ja  v a2 s. c om*/
    servlet.setLoadOnStartup(1);
}

From source file:org.tommy.stationery.moracle.core.client.server.JettyWebSocketTestServer.java

@Override
public void deployConfig(WebApplicationContext cxt) {
    ServletContextHandler contextHandler = new ServletContextHandler();
    ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(cxt));
    contextHandler.addServlet(servletHolder, "/");
    this.jettyServer.setHandler(contextHandler);
}

From source file:net.oneandone.stool.overview.initializer.ApplicationInitializer.java

@Override
public void afterSpringSecurityFilterChain(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext context;
    ServletRegistration.Dynamic dispatcher;

    context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("net.oneandone.stool.overview.config");
    servletContext.addListener(new ContextLoaderListener(context));
    dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);/*  ww w  .  j a  va 2 s . co m*/
    dispatcher.addMapping("/");
}