Package org.springframework.web.context.support

Examples of org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refresh()


  @Test
  public void explicitValidator() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MyValidatorConfiguration.class);
    context.setServletContext(new MockServletContext());
    context.refresh();

    context.getBean(Validator.class); // Fails as there are two Validator beans in the context
  }

  @Test
View Full Code Here


    log.debug("${artifactId} starting up...");

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(SpringConfiguration.class);
    ctx.refresh();
   
    // Register the Spring Context in the ServletContext
    sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);

    // Manages the lifecycle
View Full Code Here

  @Test
  public void noExplicitValidator() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MyConfiguration.class);
    context.setServletContext(new MockServletContext());
    context.refresh(); // Fails as there's no Validator bean in the context
  }

}

@Configuration
View Full Code Here

  }

  private void setup(Class<?> configurationClass) {
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(configurationClass);
    applicationContext.refresh();
    this.applicationContext = applicationContext;
    ContextLoaderTestUtils.setCurrentWebApplicationContext(this.applicationContext);
  }

  @Test
View Full Code Here

  @Test
  public void annotationConfigWebApplicationContext() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setEnvironment(prodWebEnv);
    ctx.setConfigLocation(EnvironmentAwareBean.class.getName());
    ctx.refresh();

    assertHasEnvironment(ctx, prodWebEnv);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, prodWebEnv);
  }
View Full Code Here

    servletConfig.addInitParameter("pConfig1", "pConfig1Value");

    AbstractRefreshableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setConfigLocation(EnvironmentAwareBean.class.getName());
    ctx.setServletConfig(servletConfig);
    ctx.refresh();

    ConfigurableEnvironment environment = ctx.getEnvironment();
    assertThat(environment, instanceOf(StandardServletEnvironment.class));
    MutablePropertySources propertySources = environment.getPropertySources();
    assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
View Full Code Here

    this.filterChain = new MockFilterChain(this.servlet, new ResourceUrlEncodingFilter());

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(WebConfig.class);
    context.refresh();

    this.request = new MockHttpServletRequest("GET", "/");
    this.request.setContextPath("/myapp");
    this.response = new MockHttpServletResponse();
View Full Code Here

  private ApplicationContext initContext(Class... configClasses) {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(configClasses);
    context.refresh();
    return context;
  }


  @EnableWebMvc
View Full Code Here

    MockHttpServletResponse response = new MockHttpServletResponse();

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(configClass);
    context.setServletContext(servletContext);
    context.refresh();
    DispatcherServlet servlet = new DispatcherServlet(context);
    servlet.init(servletConfig);
    servlet.service(request, response);
    return response;
  }
View Full Code Here

  // {!begin createRootContext}
  private WebApplicationContext createRootContext(ServletContext servletContext) {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CoreConfig.class);
    rootContext.refresh();

    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.setInitParameter("defaultHtmlEscape", "true");

    return rootContext;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.