org.springframework.web.servlet.DispatcherServlet#setContextClass ( )源码实例Demo

下面列出了org.springframework.web.servlet.DispatcherServlet#setContextClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tracee   文件: WebIntegrationIT.java
@Before
public void startJetty() throws Exception {
	Tracee.getBackend().clear();

	server = new Server(new InetSocketAddress("127.0.0.1", 0));
	ServletContextHandler context = new ServletContextHandler(null, "/", ServletContextHandler.NO_SECURITY);
	final DispatcherServlet dispatcherServlet = new DispatcherServlet();
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);
	dispatcherServlet.setContextInitializerClasses(TraceeInterceptorSpringApplicationInitializer.class.getCanonicalName());
	dispatcherServlet.setContextConfigLocation(TraceeInterceptorSpringConfig.class.getName());
	context.addServlet(new ServletHolder(dispatcherServlet), "/");
	server.setHandler(context);
	server.start();
	ENDPOINT_URL = "http://" + server.getConnectors()[0].getName() + "/";

}
 
源代码2 项目: spring-analysis-note   文件: ContextLoaderTests.java
@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
	DispatcherServlet servlet = new DispatcherServlet();
	servlet.setContextClass(XmlWebApplicationContext.class);
	try {
		servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
		fail("Should have thrown BeanDefinitionStoreException");
	}
	catch (BeanDefinitionStoreException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
		assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-servlet.xml"));
	}
}
 
@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
	DispatcherServlet servlet = new DispatcherServlet();
	servlet.setContextClass(XmlWebApplicationContext.class);
	try {
		servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
		fail("Should have thrown BeanDefinitionStoreException");
	}
	catch (BeanDefinitionStoreException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
		assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-servlet.xml"));
	}
}
 
源代码4 项目: activiti6-boot2   文件: ActivitiUIApplication.java
@Bean
public ServletRegistrationBean apiDispatcher() {
    DispatcherServlet api = new DispatcherServlet();
    api.setContextClass(AnnotationConfigWebApplicationContext.class);
    api.setContextConfigLocation(ApiDispatcherServletConfiguration.class.getName());
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setServlet(api);
    registrationBean.addUrlMappings("/api/*"); // api下面的所有内容都访问到这里
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    registrationBean.setName("api"); // 不能重复,重复则以最后一个设置的为准

    return registrationBean;
}
 
源代码5 项目: activiti6-boot2   文件: ActivitiUIApplication.java
@Bean
public ServletRegistrationBean appDispatcher() {
    DispatcherServlet api = new DispatcherServlet();
    api.setContextClass(AnnotationConfigWebApplicationContext.class);
    api.setContextConfigLocation(AppDispatcherServletConfiguration.class.getName());
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setServlet(api);
    registrationBean.addUrlMappings("/app/*"); // app下面的所有内容都访问到这里
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    registrationBean.setName("app"); // 不能重复,重复则以最后一个设置的为准

    return registrationBean;
}
 
@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
	DispatcherServlet servlet = new DispatcherServlet();
	servlet.setContextClass(XmlWebApplicationContext.class);
	try {
		servlet.init(new MockServletConfig(new MockServletContext(""), "test"));
		fail("Should have thrown BeanDefinitionStoreException");
	}
	catch (BeanDefinitionStoreException ex) {
		// expected
		assertTrue(ex.getCause() instanceof IOException);
		assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-servlet.xml"));
	}
}
 
private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setContextConfigLocation(configLocation());
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");
	dispatcher.addMapping("/");
}
 
private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setContextConfigLocation(configLocation());
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");
	dispatcher.addMapping("/");
}
 
private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setContextConfigLocation(configLocation());
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");
	dispatcher.addMapping("/");
}
 
private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) {
	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setContextConfigLocation(configLocation());
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");
	dispatcher.addMapping("/");
}