Example usage for org.springframework.web.context.support StaticWebApplicationContext setParent

List of usage examples for org.springframework.web.context.support StaticWebApplicationContext setParent

Introduction

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

Prototype

@Override
public void setParent(@Nullable ApplicationContext parent) 

Source Link

Document

Set the parent of this application context, also setting the parent of the internal BeanFactory accordingly.

Usage

From source file:org.hdiv.AbstractHDIVTestCase.java

protected final void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }//w  w w . jav  a  2  s  .  c  om

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}

From source file:org.hdiv.hateoas.jackson.AbstractHDIVTestCase.java

protected void setUp() throws Exception {

    String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml",
            "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml",
            "/org/hdiv/config/applicationContext-extra.xml" };

    if (this.applicationContext == null) {
        this.applicationContext = new ClassPathXmlApplicationContext(files);
    }/*from w ww .java2  s  .c  o  m*/

    // Servlet API mock
    HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest");
    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Put Spring context on ServletContext
    StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setParent(this.applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            webApplicationContext);

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean("config");

    InitListener initListener = new InitListener();
    // Initialize ServletContext
    ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext);
    initListener.contextInitialized(servletContextEvent);
    // Initialize HttpSession
    HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession);
    initListener.sessionCreated(httpSessionEvent);
    // Initialize request
    ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request);
    initListener.requestInitialized(requestEvent);

    if (log.isDebugEnabled()) {
        log.debug("Hdiv test context initialized");
    }

    onSetUp();
}