Search in sources :

Example 26 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithNoMultipartUndertowConfiguration.

@Test
public void webServerWithNoMultipartUndertowConfiguration() {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithNoMultipartUndertow.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    verifyServletWorks();
    assertThat(servlet.getMultipartResolver()).isNotNull();
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 27 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithNoMultipartTomcatConfiguration.

@Test
public void webServerWithNoMultipartTomcatConfiguration() {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithNoMultipartTomcat.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    assertThat(servlet.getMultipartResolver()).isNull();
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
    verifyServletWorks();
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 28 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithNoMultipartJettyConfiguration.

@Test
public void webServerWithNoMultipartJettyConfiguration() {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithNoMultipartJetty.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    assertThat(servlet.getMultipartResolver()).isNotNull();
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
    verifyServletWorks();
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 29 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-framework by spring-projects.

the class DefaultMockMvcBuilderTests method dispatcherServletCustomizerProcessedInOrder.

@Test
public void dispatcherServletCustomizerProcessedInOrder() {
    StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext);
    DefaultMockMvcBuilder builder = webAppContextSetup(root);
    builder.addDispatcherServletCustomizer(ds -> ds.setContextId("test-id"));
    builder.addDispatcherServletCustomizer(ds -> ds.setContextId("override-id"));
    builder.dispatchOptions(true);
    MockMvc mvc = builder.build();
    DispatcherServlet ds = (DispatcherServlet) new DirectFieldAccessor(mvc).getPropertyValue("servlet");
    assertEquals("override-id", ds.getContextId());
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 30 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project Activiti by Activiti.

the class JPAWebConfigurer method initSpring.

/**
   * Initializes Spring and Spring MVC.
   */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    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;
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Aggregations

DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)33 Test (org.junit.Test)16 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)14 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)7 WebApplicationContext (org.springframework.web.context.WebApplicationContext)6 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 ServletRegistration (javax.servlet.ServletRegistration)4 Server (org.eclipse.jetty.server.Server)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)4 Bean (org.springframework.context.annotation.Bean)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 InetSocketAddress (java.net.InetSocketAddress)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 Order (org.springframework.core.annotation.Order)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)3 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)3 Filter (javax.servlet.Filter)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2