Example usage for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

List of usage examples for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.

Prototype

String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

To view the source code for org.springframework.web.context WebApplicationContext ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE.

Click Source Link

Document

Context attribute to bind root WebApplicationContext to on successful startup.

Usage

From source file:org.springside.modules.test.spring.SpringWebTestHelper.java

/**
 * ServletContext?Spring WebApplicationContext.
 * /*from  w ww. j av  a 2 s  .com*/
 * @param applicationContext ApplicationContext.
 */
public static void initWebApplicationContext(MockServletContext servletContext,
        ApplicationContext applicationContext) {
    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(applicationContext);
    wac.setServletContext(servletContext);
    wac.setConfigLocation("");
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    wac.refresh();
}

From source file:cn.buk.qms.listener.QuartzContextListener.java

@Override
public void contextDestroyed(ServletContextEvent arg0) {
    WebApplicationContext webApplicationContext = (WebApplicationContext) arg0.getServletContext()
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

    Object obj = webApplicationContext.getBean("ctripHotelService");
    //System.out.println(obj);
    cn.buk.api.service.CtripHotelServiceImpl ctripHotelService = (cn.buk.api.service.CtripHotelServiceImpl) obj;
    if (ctripHotelService != null) {
        ctripHotelService.stopService();
        System.out.println("ctripHotelService.stopService();");
        try {/*  w  w w  .j a  v a2s. c  o  m*/
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    obj = null;
    System.out.println("Obj: " + obj);
    obj = webApplicationContext.getBean("hotelService");
    System.out.println("Obj: " + obj);
    //if(obj != null) {
    //cn.buk.hotel.service.HotelServiceImpl hotelService = ;
    //System.out.println("hotelService: " + hotelService);

    System.out.println("hotelService.stopService();");

    ((cn.buk.hotel.service.HotelServiceImpl) obj).stopService();

    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    //}

    obj = webApplicationContext.getBean("startQuartz");
    //System.out.println(obj.getClass().getName());
    org.quartz.impl.StdScheduler startQuartz = (org.quartz.impl.StdScheduler) obj;
    if (startQuartz != null) {
        //System.out.println("startQuertz.shutdown();");
        startQuartz.shutdown();
    }
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.cabig.ctms.web.filters.BeansInRequestFilterTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    applicationContext = registerMockFor(WebApplicationContext.class);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            applicationContext);/* w w  w  .ja  va  2s . c o  m*/
    filterConfig = new MockFilterConfig(servletContext);
    filterChain = registerMockFor(FilterChain.class);
    filter = new BeansInRequestFilter();
}

From source file:com.github.mcs.sst.SpringTestHelper.java

/**
 * Injects Spring managed beans using a Web Application Context derived from
 * the ServletContext./*from  www  .java  2  s . c om*/
 *
 * @param bean the object to have beans injected into
 * @param ctx the ServletContext to use to find the Spring ApplicationContext
 */
public static void injectBeans(Object bean, ServletContext ctx) {
    ApplicationContext ac = (ApplicationContext) ctx
            .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    injectBeans(bean, ac);
}

From source file:gov.nih.nci.cabig.ctms.web.filters.ContextRetainingFilterAdapterTest.java

public void testGetApplicationContext() throws Exception {
    expectRetainServletContext();/*from  www .j a v  a 2  s. c  om*/
    WebApplicationContext applicationContext = createMock(WebApplicationContext.class);
    replay(applicationContext);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            applicationContext);

    assertSame("Application context not correct", applicationContext, adapter.getApplicationContext());
    verify(applicationContext);
}

From source file:test.pl.chilldev.web.spring.context.SpringBeansFacesPageMetaModelResolverTest.java

@Test
public void getPageMetaModel() throws PageMetaModelContextException {
    FaceletContext faceletContext = new MockFaceletContext();
    faceletContext.getFacesContext().getExternalContext().getApplicationMap()
            .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.appContext);

    PageMetaModelResolver resolver = new SpringBeansFacesPageMetaModelResolver();
    PageMetaModel page = new PageMetaModel();

    when(this.appContext.getBean(PageMetaModel.class)).thenReturn(page);

    assertSame(//from w ww  .  jav a  2s  . c o  m
            "SpringBeansFacesPageMetaModelResolver.getPageMetaModel() should return page model from Spring container.",
            page, resolver.getPageMetaModel(faceletContext));
}

From source file:test.pl.chilldev.web.spring.context.SpringBeansJspPageMetaModelResolverTest.java

@Test
public void getPageMetaModel() throws PageMetaModelContextException {
    PageContext jspContext = new MockPageContext();
    jspContext.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            this.appContext);

    PageMetaModelResolver resolver = new SpringBeansJspPageMetaModelResolver();
    PageMetaModel page = new PageMetaModel();

    when(this.appContext.getBean(PageMetaModel.class)).thenReturn(page);

    assertSame(//from   w ww . j a  v  a 2  s .  c  o  m
            "SpringBeansJspPageMetaModelResolver.getPageMetaModel() should return page model from Spring container.",
            page, resolver.getPageMetaModel(jspContext));
}

From source file:com.google.code.struts2.test.junit.StrutsSpringTest.java

@Override
protected void setupBeforeInitDispatcher() throws Exception {
    this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            applicationContext);//from w w w.  java 2s  .com
}

From source file:sindica.to.dropwizard.spring.servlet.SpringContextLoaderListener.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    sce.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    context.setServletContext(sce.getServletContext());
}

From source file:com.google.code.struts2.test.junit.StrutsSpringSessionTest.java

@Override
protected void setupBeforeInitDispatcher() throws Exception {
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            applicationContext);//  ww  w . j a va 2  s .co m
}