Package org.springframework.web.context.support

Examples of org.springframework.web.context.support.XmlWebApplicationContext


        ConnectionFactory connectionFactory = (ConnectionFactory)context.getBean("connectionFactory");
        servletContext.setAttribute(WebClient.CONNECTION_FACTORY_ATTRIBUTE, connectionFactory);
    }

    public void contextDestroyed(ServletContextEvent event) {
        XmlWebApplicationContext context = (XmlWebApplicationContext)WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
        if (context != null) {
            context.stop();
            context.destroy();
        }
        // do nothing, since the context is destroyed anyway
    }
View Full Code Here


   *
   * @return application context instance
   */
  protected ConfigurableWebApplicationContext newApplicationContext()
  {
    return new XmlWebApplicationContext();
  }
View Full Code Here

  private ApplicationContext context;

  @Before
  public void setUp() {
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setConfigLocations(new String[] {CONTEXT});
    wac.refresh();
    this.context = wac;
  }
View Full Code Here

    assertEnvironmentAwareInvoked(ctx, prodWebEnv);
  }

  @Test
  public void xmlWebApplicationContext() {
    AbstractRefreshableWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("classpath:" + XML_PATH);
    ctx.setEnvironment(prodWebEnv);
    ctx.refresh();

    assertHasEnvironment(ctx, prodWebEnv);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, prodWebEnv);
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
  }
View Full Code Here

  private ConfigurableWebApplicationContext wac;

  @Override
  public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    wac = new XmlWebApplicationContext();
    wac.setServletContext(sc);
    wac.setConfigLocations(new String[] {CONF});
    wac.refresh();
  }
View Full Code Here

  private HandlerMapping hm;

  @Override
  public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    this.wac = new XmlWebApplicationContext();
    this.wac.setServletContext(sc);
    this.wac.setConfigLocations(new String[] {LOCATION});
    this.wac.refresh();
    this.hm = (HandlerMapping) this.wac.getBean("mapping");
  }
View Full Code Here

  private HandlerMapping hm4;

  @Override
  public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    this.wac = new XmlWebApplicationContext();
    this.wac.setServletContext(sc);
    this.wac.setConfigLocations(new String[] {LOCATION});
    this.wac.refresh();
    this.hm = (HandlerMapping) this.wac.getBean("mapping");
    this.hm2 = (HandlerMapping) this.wac.getBean("mapping2");
View Full Code Here

public class SimpleUrlHandlerMappingTests {

  @Test
  public void handlerBeanNotFound() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext root = new XmlWebApplicationContext();
    root.setServletContext(sc);
    root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"});
    root.refresh();
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("map2err");
    wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"});
    try {
      wac.refresh();
      fail("Should have thrown NoSuchBeanDefinitionException");
    }
    catch (FatalBeanException ex) {
      NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
      assertEquals("mainControlle", nestedEx.getBeanName());
View Full Code Here

    assertSame(controller, hec.getHandler());
  }

  private void checkMappings(String beanName) throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setServletContext(sc);
    wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2.xml"});
    wac.refresh();
    Object bean = wac.getBean("mainController");
    Object otherBean = wac.getBean("otherController");
    Object defaultBean = wac.getBean("starController");
    HandlerMapping hm = (HandlerMapping) wac.getBean(beanName);

    MockHttpServletRequest req = new MockHttpServletRequest("GET", "/welcome.html");
    HandlerExecutionChain hec = getHandler(hm, req);
    assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
    assertEquals("/welcome.html", req.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE));
View Full Code Here

      this.applicationContext.getBeanDefinitionCount() == 14);
  }

  public void testWithoutMessageSource() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("testNamespace");
    wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
    wac.refresh();
    try {
      wac.getMessage("someMessage", null, Locale.getDefault());
      fail("Should have thrown NoSuchMessageException");
    }
    catch (NoSuchMessageException ex) {
      // expected;
    }
    String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
    assertTrue("Default message returned", "default".equals(msg));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.context.support.XmlWebApplicationContext

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.