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:org.statefulj.demo.ddd.config.MVCInitializer.java

@Override
protected void registerDispatcherServlet(ServletContext servletContext) {
    String servletName = getServletName();

    WebApplicationContext servletAppContext = createServletApplicationContext();

    DispatcherServlet dispatcherServlet = new DispatcherServlet(servletAppContext);

    // throw NoHandlerFoundException to Controller when a User requests a non-existent page
    ///*from  w w  w . ja v  a 2 s .c o  m*/
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

    ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet);

    registration.setLoadOnStartup(1);
    registration.addMapping(getServletMappings());
    registration.setAsyncSupported(isAsyncSupported());

    Filter[] filters = getServletFilters();
    if (!ObjectUtils.isEmpty(filters)) {
        for (Filter filter : filters) {
            registerServletFilter(servletContext, filter);
        }
    }

    customizeRegistration(registration);
}

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

public void onStartup(ServletContext servletContext) throws ServletException {

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

    final DispatcherServlet dispatcherServlet = new DispatcherServlet(webAppContext);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);/*from  ww  w . j  a  va  2  s.  co m*/
    dispatcher.addMapping("/site/*");

    UrlRewriteFilter urlRewriteFilter = new UrlRewriteFilter();

    servletContext.addFilter("UrlRewriteFilter", urlRewriteFilter)
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");

}

From source file:com.github.marsbits.restfbmessenger.sample.EchoWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation(this.getClass().getPackage().getName());
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
            new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);/*from   w ww.ja  v  a  2s . co m*/
    dispatcher.addMapping("/*");
}

From source file:at.ac.tuwien.infosys.configuration.WebAppInitializer.java

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

    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();

    root.scan("at.ac.tuwien.infosys");

    context.addListener(new ContextLoaderListener(root));

    final ServletRegistration.Dynamic appServlet = context.addServlet("appServlet",
            new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setAsyncSupported(true);/*from   w  w w  . ja  va 2 s  .c o  m*/
    appServlet.setLoadOnStartup(1);
    appServlet.addMapping("/*");
}

From source file:com.googlecode.jeeunit.example.spring.web.LibraryWebApplicationInitializer.java

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

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().addActiveProfile("web");
    rootContext.register(WebSpringConfig.class);
    sc.addListener(new ContextLoaderListener(rootContext));

    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.setParent(rootContext);
    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcher",
            new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(2);/*from  w  w w . j a va2s  .  com*/
    dispatcher.addMapping("*.html");
    dispatcher.addMapping("*.form");
    dispatcher.addMapping("*.ajax");
}

From source file:org.osgpfoundation.osgp.webdemoapp.application.config.WebDemoInitializer.java

@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    try {/*from   w  ww.j  ava 2 s  .  c o m*/
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

        final Context initialContext = new InitialContext();

        final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationContext.class);

        final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
                new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

        servletContext.addListener(new ContextLoaderListener(rootContext));
    } catch (final NamingException e) {
        throw new ServletException("naming exception", e);
    }
}

From source file:ru.war.name.application.config.Initializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    // ??   Spring ?
    ctx.register(SpringWebConfig.class);
    ctx.register(SpringSecurityConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);/*from  ww w . java 2 s . com*/
}

From source file:codingsaint.paymentgateway.config.WebInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(Configurations.class);
    ctx.setServletContext(servletContext);
    Dynamic servlet = servletContext.addServlet("spring", new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(LOAD_ON_STARTUP);

}

From source file:org.ado.biblio.config.AppInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(container);// ww  w  .  j av  a 2 s  .  co m

    ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/*");
}

From source file:com.kajj.tools.logviewer.config.LogViewerWebApplicationInitializer.java

/**
 * Initialization method for the ServletContext. Creates the Spring context and
 * DispatcherServlet.//from  w w  w. j  a v  a  2  s  . c o m
 *
 * @param servletContext The ServletContext to initialize.
 * @throws ServletException If the ServletContext fails to initialize.
 */
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    final AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext();
    springContext.setConfigLocation("com.kajj.tools.logviewer.config");
    servletContext.addListener(new ContextLoaderListener(springContext));

    final DispatcherServlet servlet = new DispatcherServlet(springContext);
    final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, servlet);
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping(MAPPING_ANY);
}