Example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils getRequiredWebApplicationContext.

Prototype

public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc)
        throws IllegalStateException 

Source Link

Document

Find the root WebApplicationContext for this web app, typically loaded via org.springframework.web.context.ContextLoaderListener .

Usage

From source file:org.bindgen.wicket.phonebook.web.PhonebookApplication.java

@Override
public ApplicationContext context() {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

From source file:sf.wicketlearningapplication.WicketLearningApplication.java

public ApplicationContext getApplicationContext() {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}

From source file:com.enonic.cms.web.portal.PortalServlet.java

@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);

    final ServletContext context = config.getServletContext();
    final WebApplicationContext springContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(context);
    this.dispatcher = springContext.getBean(RequestDispatcher.class);
}

From source file:com.sbu.controller.AddJobServlet.java

@Override
public void init() throws ServletException {
    WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServletContext());
    employerService = context.getBean(EmployerManager.class);
}

From source file:com.sonoport.spring.SessionListener.java

@Override
public void sessionCreated(HttpSessionEvent event) {
    final ServletContext servletContext = event.getSession().getServletContext();
    final WebApplicationContext context = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    ApplicationContextLocator.setApplicationContext(context);
}

From source file:net.chrisrichardson.foodToGo.ui.domain.servlets.BaseSpringServlet.java

/**
 * Gets the bean from the web application context
 * @param name//from   w w w.  j  a va2  s.  c  o  m
 * @param type
 * @return
 */
protected Object getBean(String name, Class type) {
    return WebApplicationContextUtils.getRequiredWebApplicationContext(sc.getServletContext()).getBean(name,
            type);
}

From source file:gov.nih.nci.ncicb.cadsr.umlmodelbrowser.struts.common.SpringWebContextPlugIn.java

/**
 * Intializer. Instantiates a new object and adds it to the application context by key
 *
 * @param servlet The ActionServlet for our application
 * @param config  The ModuleConfig for our owning module
 * @throws ServletException if we cannot configure ourselves correctly
 */// ww  w.  j  a  v a  2 s . com
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    this.servlet = servlet;
    try {
        ServletContext servletContext = servlet.getServletContext();
        SpringObjectLocatorImpl.applicationContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(servletContext);

    } catch (Exception e) {

        throw new ServletException("Could not initalize SpringObjectLocatorImpl.applicationContext", e);
    }

}

From source file:org.beanfuse.security.monitor.OnlineUserListener.java

/**
 * session? ?session/*from www.jav  a  2 s  .  c o  m*/
 */
public void sessionDestroyed(HttpSessionEvent event) {
    if (null == monitor) {
        WebApplicationContext wac = WebApplicationContextUtils
                .getRequiredWebApplicationContext(event.getSession().getServletContext());
        monitor = (SecurityMonitor) wac.getBean("securityMonitor", SecurityMonitor.class);
    }
    monitor.logout(event.getSession());
}

From source file:gov.nih.nci.ncicb.cadsr.common.struts.common.SpringWebContextPlugIn.java

/**
 * Intializer. Instantiates a new object and adds it to the application context by key
 *
 * @param servlet The ActionServlet for our application
 * @param config  The ModuleConfig for our owning module
 * @throws ServletException if we cannot configure ourselves correctly
 *//*from  w ww .  j ava 2  s  .  c  om*/
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    System.out.println(config.toString() + " init " + servlet.toString());
    this.servlet = servlet;
    try {
        ServletContext servletContext = servlet.getServletContext();
        SpringObjectLocatorImpl.applicationContext = WebApplicationContextUtils
                .getRequiredWebApplicationContext(servletContext);

    } catch (Exception e) {

        throw new ServletException("Could not initalize SpringObjectLocatorImpl.applicationContext", e);
    }

}

From source file:gov.nih.nci.cabig.caaers.web.tags.RenderDecisionManagerTag.java

@Override
public int doStartTag() throws JspException {
    //validate parameters
    validateParameters();/*from w w  w.jav  a 2 s .  c  o  m*/

    ApplicationContext appContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(pageContext.getServletContext());
    RenderDecisionManager renderDecisionManager = (RenderDecisionManager) appContext
            .getBean("renderDecisionManagerBean");

    boolean decision = false;
    if (uiType.equals(UI_TYPE_DIVISION)) {
        decision = renderDecisionManager.canRenderSection(elementID,
                (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
    }
    if (uiType.equals(UI_TYPE_FIELD)) {
        decision = renderDecisionManager.canRenderField(elementID,
                (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
    }

    return (decision) ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY;
}