Example usage for org.springframework.web.context.support GenericWebApplicationContext GenericWebApplicationContext

List of usage examples for org.springframework.web.context.support GenericWebApplicationContext GenericWebApplicationContext

Introduction

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

Prototype

public GenericWebApplicationContext() 

Source Link

Document

Create a new GenericWebApplicationContext.

Usage

From source file:com.enonic.cms.server.service.portal.mvc.controller.XmlWebApplicationContextLoader.java

public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading ApplicationContext for locations ["
                + StringUtils.arrayToCommaDelimitedString(locations) + "].");
    }/*from  w  ww .j  a  v a2s  .  c o m*/
    GenericApplicationContext context = new GenericWebApplicationContext();
    prepareContext(context);
    customizeBeanFactory(context.getDefaultListableBeanFactory());
    createBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    customizeContext(context);
    context.refresh();
    context.registerShutdownHook();
    return context;
}

From source file:at.ac.tuwien.infosys.configuration.WebAppInitializer.java

@Override
public void onStartup(final ServletContext context) throws ServletException {

    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();

    root.scan("at.ac.tuwien.infosys");

    context.addListener(new ContextLoaderListener(root));

    final ServletRegistration.Dynamic appServlet = context.addServlet("appServlet",
            new DispatcherServlet(new GenericWebApplicationContext()));
    appServlet.setAsyncSupported(true);//from  w  w  w. j  av a2s  .c  o  m
    appServlet.setLoadOnStartup(1);
    appServlet.addMapping("/*");
}

From source file:com.gu.management.spring.ManagementUrlDiscoveryServiceTest.java

@Before
public void init() throws Exception {
    MockitoAnnotations.initMocks(this);
    mapping = new SimpleUrlHandlerMapping();
    mapping.setApplicationContext(new GenericWebApplicationContext());
}

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

@Test(expected = PageMetaModelContextException.class)
public void getPageMetaModelWithoutBean() throws PageMetaModelContextException {
    GenericWebApplicationContext appContext = new GenericWebApplicationContext();
    appContext.refresh();//from w w  w.j ava 2s.c o m
    FaceletContext faceletContext = new MockFaceletContext();
    faceletContext.getFacesContext().getExternalContext().getApplicationMap()
            .put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    PageMetaModelResolver resolver = new SpringBeansFacesPageMetaModelResolver();
    resolver.getPageMetaModel(faceletContext);
}

From source file:com.wbss.mycoffee.in.helper.spring.WebContextLoader.java

@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {

    final GenericWebApplicationContext webContext = new GenericWebApplicationContext();
    SERVLET_CONTEXT.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
    webContext.setServletContext(SERVLET_CONTEXT);
    createBeanDefinitionReader(webContext).loadBeanDefinitions(mergedConfig.getLocations());
    AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
    webContext.refresh();//from   w ww. j av  a2  s. c  o m
    webContext.registerShutdownHook();
    return webContext;
}

From source file:org.hdiv.web.servlet.config.MvcNamespaceTests.java

@Before
public void setUp() {
    appContext = new GenericWebApplicationContext();
    appContext.setServletContext(new MockServletContext());
    LocaleContextHolder.setLocale(Locale.US);
}

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

@Test(expected = PageMetaModelContextException.class)
public void getPageMetaModelWithoutBean() throws PageMetaModelContextException {
    GenericWebApplicationContext appContext = new GenericWebApplicationContext();
    appContext.refresh();// w  ww.j  a va  2 s .c o  m
    PageContext jspContext = new MockPageContext();
    jspContext.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            appContext);

    PageMetaModelResolver resolver = new SpringBeansJspPageMetaModelResolver();
    resolver.getPageMetaModel(jspContext);
}

From source file:com.autentia.wuija.spring.TestContextLoader.java

@Override
public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("Loading ApplicationContext for locations ["
                + StringUtils.arrayToCommaDelimitedString(locations) + "].");
    }/*from  ww  w. ja v a  2  s .c o  m*/

    final GenericWebApplicationContext context = new GenericWebApplicationContext();

    customizeBeanFactory(context.getDefaultListableBeanFactory());
    createBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    customizeContext(context);

    context.refresh();
    context.registerShutdownHook();

    return context;
}

From source file:fr.letitzen.demo.web.GenericWebXmlContextLoader.java

public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
    prepareContext(context);/*  w  ww . java 2s.c  o m*/
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    context.registerShutdownHook();
    return context;
}

From source file:grgr.test.cxf.UndertowCxfTest.java

@Test
public void testUndertowServlet() throws Exception {

    ServletContainer servletContainer = Servlets.newContainer();

    // parent, webcontext-wide Spring context
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("/UndertowCxfTest-context.xml");

    // represents a servlet deployment - representing everything we can find in web.xml
    DeploymentInfo di = Servlets.deployment().setClassLoader(UndertowCxfTest.class.getClassLoader())
            .setContextPath("/").setDeploymentName("ROOT.war").setDisplayName("Default Application")
            .setUrlEncoding("UTF-8").addServlets(
                    Servlets.servlet("cxf", CXFServlet.class, new ImmediateInstanceFactory<>(new CXFServlet()))
                            .addMapping("/*"));

    DeploymentManager dm = servletContainer.addDeployment(di);
    dm.deploy();/*from w  w w .  jav a  2  s. co m*/
    HttpHandler handler = dm.start();

    // parent, webcontext-wide Spring web context
    GenericWebApplicationContext wac = new GenericWebApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(dm.getDeployment().getServletContext());

    wac.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    wac.refresh();

    PathHandler path = Handlers.path().addPrefixPath(di.getContextPath(), Handlers.requestDump(handler));

    createAndStartServlet(8000, path);
}