Java Code Examples for org.springframework.web.servlet.DispatcherServlet#setContextConfigLocation()

The following examples show how to use org.springframework.web.servlet.DispatcherServlet#setContextConfigLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebIntegrationIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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() + "/";

}
 
Example 2
Source File: ContextLoaderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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"));
}
 
Example 3
Source File: ContextLoaderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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"));
}
 
Example 4
Source File: ActivitiUIApplication.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: ActivitiUIApplication.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: ContextLoaderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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"));
}
 
Example 7
Source File: WebApplicationConfiguration.java    From junit-servers with MIT License 5 votes vote down vote up
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("/");
}
 
Example 8
Source File: WebApplicationConfiguration.java    From junit-servers with MIT License 5 votes vote down vote up
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("/");
}
 
Example 9
Source File: WebApplicationConfiguration.java    From junit-servers with MIT License 5 votes vote down vote up
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("/");
}
 
Example 10
Source File: WebApplicationConfiguration.java    From junit-servers with MIT License 5 votes vote down vote up
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("/");
}