use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.
the class DispatcherServletAutoConfigurationTests method registrationOverrideWithDispatcherServletWrongName.
// If a DispatcherServlet instance is registered with a name different
// from the default one, we're registering one anyway
@Test
public void registrationOverrideWithDispatcherServletWrongName() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(CustomDispatcherServletWrongName.class, DispatcherServletAutoConfiguration.class);
this.context.setServletContext(new MockServletContext());
this.context.refresh();
ServletRegistrationBean<?> registration = this.context.getBean(ServletRegistrationBean.class);
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/]");
assertThat(registration.getServletName()).isEqualTo("dispatcherServlet");
assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length).isEqualTo(2);
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.
the class ServletWebServerFactoryAutoConfigurationTests method verifyContext.
private void verifyContext() {
MockServletWebServerFactory factory = getWebServerFactory();
Servlet servlet = this.context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class);
verify(factory.getServletContext()).addServlet("dispatcherServlet", servlet);
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-framework by spring-projects.
the class ContextLoaderTests method testFrameworkServletWithCustomLocation.
@Test
public void testFrameworkServletWithCustomLocation() throws Exception {
DispatcherServlet servlet = new DispatcherServlet();
servlet.setContextConfigLocation("/org/springframework/web/context/WEB-INF/testNamespace.xml " + "/org/springframework/web/context/WEB-INF/context-addition.xml");
servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
assertTrue(servlet.getWebApplicationContext().containsBean("kerry"));
assertTrue(servlet.getWebApplicationContext().containsBean("kerryX"));
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-framework by spring-projects.
the class ViewResolutionIntegrationTests method runTest.
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
String basePath = "org/springframework/web/servlet/config/annotation";
MockServletContext servletContext = new MockServletContext(basePath);
MockServletConfig servletConfig = new MockServletConfig(servletContext);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(configClass);
context.setServletContext(servletContext);
context.refresh();
DispatcherServlet servlet = new DispatcherServlet(context);
servlet.init(servletConfig);
servlet.service(request, response);
return response;
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-framework by spring-projects.
the class CglibProxyControllerTests method initServlet.
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setProxyTargetClass(true);
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
Aggregations