Example usage for org.springframework.web.context ContextLoader closeWebApplicationContext

List of usage examples for org.springframework.web.context ContextLoader closeWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context ContextLoader closeWebApplicationContext.

Prototype

public void closeWebApplicationContext(ServletContext servletContext) 

Source Link

Document

Close Spring's web application context for the given servlet context.

Usage

From source file:architecture.ee.component.core.lifecycle.BootstrapImpl.java

public void shutdown(ServletContext servletContext) {
    lock.lock();/*from   w  ww.  j a  v  a  2  s. com*/
    try {
        if (bootstrapAdminServiceEnabled.get()) {
            AdminService adminService = getAdminService();
            adminService.stop();
            adminService.destroy();
        } else {
            ContextLoader contextLoader = getBootstrapComponent(ContextLoader.class);
            contextLoader.closeWebApplicationContext(servletContext);
        }
    } finally {
        initialized.set(false);
        lock.unlock();
    }
}

From source file:net.jawr.web.bundle.processor.spring.SpringControllerBundleProcessor.java

/**
 * Initialize the servlets which will handle the request to the JawrSpringController 
 * @param servletContext the servlet context
 * @return the list of servlet definition for the JawrSpringControllers
 * @throws ServletException if a servlet exception occurs
 *//*from   w  ww.j  a v a 2  s.c  om*/
@SuppressWarnings("rawtypes")
public List<ServletDefinition> initJawrSpringServlets(ServletContext servletContext) throws ServletException {

    List<ServletDefinition> jawrServletDefinitions = new ArrayList<ServletDefinition>();
    ContextLoader contextLoader = new ContextLoader();
    WebApplicationContext applicationCtx = contextLoader.initWebApplicationContext(servletContext);
    Map<?, ?> jawrControllersMap = applicationCtx.getBeansOfType(JawrSpringController.class);

    Iterator<?> entrySetIterator = jawrControllersMap.entrySet().iterator();
    while (entrySetIterator.hasNext()) {

        JawrSpringController jawrController = (JawrSpringController) ((Map.Entry) entrySetIterator.next())
                .getValue();
        Map<String, Object> initParams = new HashMap<String, Object>();
        initParams.putAll(jawrController.getInitParams());
        ServletConfig servletConfig = new MockServletConfig(SPRING_DISPATCHER_SERVLET, servletContext,
                initParams);
        MockJawrSpringServlet servlet = new MockJawrSpringServlet(jawrController, servletConfig);
        ServletDefinition servletDefinition = new ServletDefinition(servlet, servletConfig);
        jawrServletDefinitions.add(servletDefinition);
    }

    contextLoader.closeWebApplicationContext(servletContext);
    return jawrServletDefinitions;
}

From source file:org.openmrs.web.filter.update.UpdateFilter.java

/**``
 * Do everything to get openmrs going./* ww w . j  a  v  a  2  s  .com*/
 *
 * @param servletContext the servletContext from the filterconfig
 * @see Listener#startOpenmrs(ServletContext)
 */
private void startOpenmrs(ServletContext servletContext) throws Exception {
    // start spring
    // after this point, all errors need to also call: contextLoader.closeWebApplicationContext(event.getServletContext())
    // logic copied from org.springframework.web.context.ContextLoaderListener
    ContextLoader contextLoader = new ContextLoader();
    contextLoader.initWebApplicationContext(servletContext);

    try {
        WebDaemon.startOpenmrs(servletContext);
    } catch (Exception exception) {
        contextLoader.closeWebApplicationContext(servletContext);
        throw exception;
    }
}