Java Code Examples for org.springframework.web.context.support.XmlWebApplicationContext#registerShutdownHook()

The following examples show how to use org.springframework.web.context.support.XmlWebApplicationContext#registerShutdownHook() . 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: MockTdsContextLoader.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public ApplicationContext loadContext(String... locations) throws Exception {
  final MockServletContext servletContext = new MockTdsServletContext();
  final MockServletConfig servletConfig = new MockServletConfig(servletContext);
  final XmlWebApplicationContext webApplicationContext = new XmlWebApplicationContext();

  servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
  webApplicationContext.setServletConfig(servletConfig);
  webApplicationContext.setConfigLocations(locations);
  webApplicationContext.refresh();

  TdsContext tdsContext = webApplicationContext.getBean(TdsContext.class);
  checkContentRootPath(webApplicationContext, tdsContext);

  webApplicationContext.registerShutdownHook();

  return webApplicationContext;
}
 
Example 2
Source File: TestContextLoader.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public ApplicationContext loadContext (String... locations) throws Exception
{
   XmlWebApplicationContext ctx = new XmlWebApplicationContext ();
   ctx.setConfigLocations (locations);
   ctx.getEnvironment ().setActiveProfiles ("test");
   ctx.refresh ();
   AnnotationConfigUtils.registerAnnotationConfigProcessors (
      (BeanDefinitionRegistry) ctx.getBeanFactory ());
   ctx.registerShutdownHook ();
   return ctx;
}
 
Example 3
Source File: InterAccountSNSPermissionTest.java    From spring-integration-aws with MIT License 5 votes vote down vote up
private ServletContextHandler getServletContextHandler() throws Exception {

		context = new XmlWebApplicationContext();
		context.setConfigLocation("src/main/webapp/WEB-INF/InterAccountSNSPermissionFlow.xml");
		context.registerShutdownHook();

		ServletContextHandler contextHandler = new ServletContextHandler();
		contextHandler.setErrorHandler(null);
		contextHandler.setResourceBase(".");
		ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(
				context));
		contextHandler.addServlet(servletHolder, "/*");

		return contextHandler;
	}
 
Example 4
Source File: MockServletContextWebContextLoader.java    From olat with Apache License 2.0 4 votes vote down vote up
@Override
public final XmlWebApplicationContext loadContext(final String... locations) throws Exception {

    System.out.println("Loading ApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "].");

    final XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    final MockServletContext servletContext = new MockServletContext();

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    appContext.setServletContext(servletContext);
    appContext.setConfigLocations(locations);
    appContext.refresh();
    appContext.registerShutdownHook();

    return appContext;

}
 
Example 5
Source File: MockServletContextWebContextLoader.java    From olat with Apache License 2.0 4 votes vote down vote up
@Override
public final XmlWebApplicationContext loadContext(final String... locations) throws Exception {

    System.out.println("Loading ApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "].");

    final XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    final MockServletContext servletContext = new MockServletContext();

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    appContext.setServletContext(servletContext);
    appContext.setConfigLocations(locations);
    appContext.refresh();
    appContext.registerShutdownHook();

    return appContext;

}