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

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

Introduction

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

Prototype

@Override
    public void refresh() throws BeansException, IllegalStateException 

Source Link

Usage

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();
    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:test.pl.chilldev.web.spring.context.SpringBeansJspPageMetaModelResolverTest.java

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

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

From source file:de.fau.amos4.test.BaseWebApplicationContextTests.java

@Before
public void initDispatcherServlet() throws Exception {
    servlet = new DispatcherServlet() {
        private static final long serialVersionUID = 1L;

        @Override//from   w w w .  ja v a2s  .  c  om
        protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
                throws BeansException {

            GenericWebApplicationContext gwac = new GenericWebApplicationContext();
            gwac.setParent(applicationContext);
            gwac.refresh();
            return gwac;
        }
    };

    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();

    MockServletContext servletContext = new MockServletContext("src/main/java/amos4/model",
            new FileSystemResourceLoader());

    servlet.init(new MockServletConfig(servletContext));
}

From source file:ca.unx.template.config.JettyConfiguration.java

@Bean
public WebAppContext jettyWebAppContext() throws IOException {

    WebAppContext ctx = new WebAppContext();
    ctx.setContextPath("/*");
    ctx.setWar(new ClassPathResource("webapp").getURI().toString());

    /* Disable directory listings if no index.html is found. */
    ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "true");

    /* Create the root web application context and set it as a servlet
     * attribute so the dispatcher servlet can find it. */
    GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
    webApplicationContext.setParent(applicationContext);
    webApplicationContext.refresh();
    ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);

    /*/* w  ww .j  a  v a 2s .  c  o m*/
     * Set the attributes that the Metrics servlets require.  The Metrics
     * servlet is added in the WebAppInitializer.
     */
    ctx.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
    ctx.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);

    ctx.addEventListener(new WebAppInitializer());

    return ctx;
}

From source file:org.spo.ifs.config.JettyConfiguration.java

@Bean
public WebAppContext webAppContext() throws IOException {

    WebAppContext ctx = new WebAppContext();
    ctx.setContextPath("/");
    ctx.setWar(new ClassPathResource("webapp").getURI().toString());

    /* Disable directory listings if no index.html is found. */
    ctx.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");

    /* Create the root web application context and set it as a servlet
     * attribute so the dispatcher servlet can find it. */
    GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext();
    webApplicationContext.setParent(applicationContext);
    webApplicationContext.refresh();

    ctx.setParentLoaderPriority(true);//from   ww w . j  a v  a2 s  . co  m

    ctx.addEventListener(new ContextLoaderListener(webApplicationContext));
    ctx.addEventListener(new WebAppInitializerLoader(new WebApplicationInitializer[] {
            new SpringWebAppInitializer(), new SpringSecurityWebAppInitializer() }));

    return ctx;
}

From source file:com.example.springsecurity.web.controllers.GenericWebContextLoader.java

protected void loadBeanDefinitions(GenericWebApplicationContext context, String[] locations) {
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    context.registerShutdownHook();//from   w  w  w  .  j ava2s .c  o  m
}

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

public ApplicationContext loadContext(String... locations) throws Exception {
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    prepareContext(context);//w w w  .  j av  a2  s .  com
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(locations);
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    context.refresh();
    context.registerShutdownHook();
    return context;
}

From source file:mx.edu.um.mateo.general.test.GenericWebXmlContextLoader.java

@Override
public ApplicationContext loadContext(String... locations) throws Exception {
    GenericWebApplicationContext context = new GenericWebApplicationContext();
    prepareContext(context);/*from  w w w  .ja  v a  2  s. c  om*/
    new XmlBeanDefinitionReader(context).loadBeanDefinitions(locations);
    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  ww w . ja  v a 2s .com*/
    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);
}

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) + "].");
    }// w  ww.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;
}