Spring Framework DispatcherServlet - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework DispatcherServlet class.

This code example shows how to use the following methods:setContextClass, setContextConfigLocation
 */ 
public class RepositoryRestDispatcherServlet extends DispatcherServlet { 
 
	private static final long serialVersionUID = 5761346441984290240L; 
 
	public RepositoryRestDispatcherServlet() { 
		configure(); 
	} 
 
	public RepositoryRestDispatcherServlet(WebApplicationContext webApplicationContext) { 
		super(webApplicationContext); 
		configure(); 
	} 
 
	private void configure() { 
		setContextClass(AnnotationConfigWebApplicationContext.class); 
		setContextConfigLocation(RepositoryRestMvcConfiguration.class.getName()); 
	} 
 
} 

7
CodeRank
This code example shows how to use the following methods:
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  @Override 
  public void contextDestroyed(ServletContextEvent sce) { 
    log.info("Destroying Web application"); 
    WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()); 
    AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac; 
    gwac.close(); 
    log.debug("Web application destroyed"); 
7
CodeRank
This code example shows how to use the following methods:
		//    ); 
 
		AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); 
		webCtx.register(RestExporterExampleRestConfig.class); 
 
		DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); 
		ServletRegistration.Dynamic reg = servletContext.addServlet("rest-exporter", dispatcherServlet); 
		reg.setLoadOnStartup(1); 
		reg.addMapping("/*"); 
 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
   */ 
  private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) { 
    log.debug("Registering Spring Security Filter"); 
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); 
 
6
CodeRank
This code example shows how to use the following methods:
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
   */ 
  private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) { 
    log.debug("Registering Spring Security Filter"); 
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); 
 
6
CodeRank
This code example shows how to use the following methods:
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
   */ 
  private void initSpringSecurity(ServletContext servletContext, EnumSet<DispatcherType> disps) { 
    log.debug("Registering Spring Security Filter"); 
    FilterRegistration.Dynamic springSecurityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); 
 
6
CodeRank
This code example shows how to use the following methods:init
		servletConfig.addInitParameter("contextConfigLocation", "classpath:test-empty-context.xml"); 
		StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext(); 
		webApplicationContext.setParent(parentContext); 
		webApplicationContext.refresh(); 
		servletConfig.getServletContext().setAttribute(WebApplicationContext.class.getName() + ".ROOT", webApplicationContext); 
		dispatchServlet = new DispatcherServlet(); 
		dispatchServlet.init(servletConfig); 
		servletTestHelper.setUp(dispatchServlet); 
		entityServletHelper = new EntityServletTestHelper(dispatchServlet); 
	} 
 
	@After 
	public void afterBase() throws Exception { 
		servletTestHelper.tearDown(); 
	} 
 
	public ServletTestHelper getServletTestHelper() { 
		return servletTestHelper; 
	} 
 
6
CodeRank
This code example shows how to use the following methods:
  @Override 
  public void onStartup(ServletContext container) { 
    XmlWebApplicationContext appContext = new XmlWebApplicationContext(); 
    appContext.setConfigLocation("/WEB-INF/applicationContext.xml"); 
 
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); 
    dispatcher.setLoadOnStartup(1); 
    dispatcher.addMapping("/"); 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:
import org.springframework.web.servlet.DispatcherServlet; 
 
/** 
 * @author Brian Wing Shun Chan 
 */ 
public class RemotingServlet extends DispatcherServlet { 
 
	public static final String CONTEXT_CLASS = 
		TunnelApplicationContext.class.getName(); 
 
	public static final String CONTEXT_CONFIG_LOCATION = 
		"/WEB-INF/remoting-servlet.xml,/WEB-INF/remoting-servlet-ext.xml"; 
 
	@Override 
	public Class<?> getContextClass() { 
		try { 
			return Class.forName(CONTEXT_CLASS); 
		} 
		catch (Exception e) { 
			_log.error(e, e); 
6
CodeRank
This code example shows how to use the following methods:
		this.serverContext = new AnnotationConfigWebApplicationContext();
		this.serverContext.register(serverConfigs);
 
		Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
		context.addApplicationListener(WsContextListener.class.getName());
		Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext)).setAsyncSupported(true);
		context.addServletMapping("/", "dispatcherServlet");
	} 
 
	private File createTempDir(String prefix) {
		try { 
			File tempFolder = File.createTempFile(prefix + ".", "." + this.port);
			tempFolder.delete();
			tempFolder.mkdir();
			tempFolder.deleteOnExit();
			return tempFolder;
		} 
		catch (IOException ex) {
			throw new RuntimeException("Unable to create temp directory", ex);
		} 
6
CodeRank