Package org.springframework.web.context

Examples of org.springframework.web.context.ContextLoader


    protected MockServletContext servletContext;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        ContextLoader contextLoader = new ContextLoader();
        servletContext = new MockServletContext();
        servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
                                        getApplicationContextPath());
        applicationContext = contextLoader.initWebApplicationContext(servletContext);
    }
View Full Code Here


    // get the sub contexts - servlet context
    ServletContext ctx = servletContext.getContext(webAppKey);
    if (ctx == null) {
      ctx = servletContext;
    }
    ContextLoader loader = new ContextLoader();
    ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx);
    appCtx.setParent(applicationContext);
    appCtx.refresh();

    ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);
View Full Code Here

    this.servletContext = new MockServletContext();

    this.webAppContext = new AnnotationConfigWebApplicationContext();
    this.webAppContext.register(Config.class);

    this.contextLoader = new ContextLoader(this.webAppContext);
    this.contextLoader.initWebApplicationContext(this.servletContext);

    this.configurator = new SpringConfigurator();
  }
View Full Code Here

  public void updateTargetUrlWithContextLoader() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);

    MockServletContext servletContext = new MockServletContext();
    ContextLoader contextLoader = new ContextLoader(wac);
    contextLoader.initWebApplicationContext(servletContext);

    try {
      RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
      wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);

      RedirectView rv = new RedirectView();
      rv.setUrl("/path");

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

      given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");

      rv.render(new ModelMap(), request, response);

      verify(mockProcessor).processUrl(request, "/path");
    }
    finally {
      contextLoader.closeWebApplicationContext(servletContext);
    }
  }
View Full Code Here

    // get the sub contexts - servlet context
    ServletContext ctx = servletContext.getContext(webAppKey);
    if (ctx == null) {
      ctx = servletContext;
    }
    ContextLoader loader = new ContextLoader();
    ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader
        .initWebApplicationContext(ctx);
    appCtx.setParent(applicationContext);
    appCtx.refresh();

    ctx.setAttribute(
View Full Code Here

    logger.info("Root context loader");
    logger.debug("Path: " + prefix);

    try {
      // instance the context loader
      ContextLoader loader = createContextLoader();
      applicationContext = (ConfigurableWebApplicationContext) loader
          .initWebApplicationContext(servletContext);
      logger.debug("Root context path: "
          + applicationContext.getServletContext().getContextPath());

      ConfigurableBeanFactory factory = applicationContext
View Full Code Here

    if (registeredContexts.contains(ctx)) {
      logger.debug("Context is already registered: " + webAppKey);
      return;
    }

    ContextLoader loader = new ContextLoader();

    ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader
        .initWebApplicationContext(ctx);
    appCtx.setParent(applicationContext);
    appCtx.refresh();

    ctx.setAttribute(
View Full Code Here

   * @param configLocations application context文件路径列表.
   */
  public static void initWebApplicationContext(MockServletContext servletContext, String... configLocations) {
    String configLocationsString = StringUtils.join(configLocations, ",");
    servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocationsString);
    new ContextLoader().initWebApplicationContext(servletContext);
  }
View Full Code Here

  /**
   * 关闭ServletContext中的Spring WebApplicationContext.
   */
  public static void closeWebApplicationContext(MockServletContext servletContext) {
    new ContextLoader().closeWebApplicationContext(servletContext);
  }
View Full Code Here

  @Override
  public ApplicationContext loadContext(String... locations) throws Exception {
    MockServletContext sc = new MockServletContext();
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
        concatLocations(locations));
    ContextLoader contextLoader = new ContextLoader();
    return contextLoader.initWebApplicationContext(sc);
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.context.ContextLoader

Copyright © 2018 www.massapicom. 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.