Package org.springframework.web.context

Examples of org.springframework.web.context.ContextLoaderListener


        ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

        servletContext.addListener(new ContextLoaderListener(rootContext));
    }
View Full Code Here


    }
   
    public void test() throws Exception {
        ContextHandler context = new ContextHandler();
        context.setContextPath("/test");
        context.setEventListeners(new EventListener[] { new ContextLoaderListener() });
        Map initParams = new HashMap();
        initParams.put("contextConfigLocation", "classpath:org/apache/servicemix/http/spring-web.xml");
        initParams.put("contextClass", XmlWebApplicationContext.class.getName());
        context.setInitParams(initParams);
        ServletHolder holder = new ServletHolder();
View Full Code Here

  @Test
  public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("programmatic.xml");
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    MockServletContext sc = new MockServletContext();

    try {
      cll.contextInitialized(new ServletContextEvent(sc));
      fail("expected exception");
    } catch (Throwable t) {
      // assert that an attempt was made to load the correct XML
      assertTrue(t.getMessage(), t.getMessage().endsWith(
          "Could not open ServletContext resource [/programmatic.xml]"));
View Full Code Here

   */
  @Test
  public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setConfigLocation("programmatic.xml");
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    MockServletContext sc = new MockServletContext();
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

    try {
      cll.contextInitialized(new ServletContextEvent(sc));
      fail("expected exception");
    } catch (Throwable t) {
      // assert that an attempt was made to load the correct XML
      assertTrue(t.getMessage(), t.getMessage().endsWith(
          "Could not open ServletContext resource [/from-init-param.xml]"));
View Full Code Here

   */
  @Test
  public void abstractRefreshableWAC_fallsBackToInitParam() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    MockServletContext sc = new MockServletContext();
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

    try {
      cll.contextInitialized(new ServletContextEvent(sc));
      fail("expected exception");
    } catch (Throwable t) {
      // assert that an attempt was made to load the correct XML
      assertTrue(t.getMessage().endsWith(
          "Could not open ServletContext resource [/from-init-param.xml]"));
View Full Code Here

      protected String[] getDefaultConfigLocations() {
        return new String[] { "/WEB-INF/custom.xml" };
      }
    };
    //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    MockServletContext sc = new MockServletContext();
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

    try {
      cll.contextInitialized(new ServletContextEvent(sc));
      fail("expected exception");
    } catch (Throwable t) {
      // assert that an attempt was made to load the correct XML
      System.out.println(t.getMessage());
      assertTrue(t.getMessage().endsWith(
View Full Code Here

   */
  @Test
  public void abstractRefreshableWAC_fallsBackToConventionBasedNaming() {
    XmlWebApplicationContext ctx = new XmlWebApplicationContext();
    //ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    MockServletContext sc = new MockServletContext();
    // no init-param set
    //sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");

    try {
      cll.contextInitialized(new ServletContextEvent(sc));
      fail("expected exception");
    } catch (Throwable t) {
      // assert that an attempt was made to load the correct XML
      System.out.println(t.getMessage());
      assertTrue(t.getMessage().endsWith(
View Full Code Here

   * Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely.
   */
  @Test
  public void genericWAC() {
    GenericWebApplicationContext ctx = new GenericWebApplicationContext();
    ContextLoaderListener cll = new ContextLoaderListener(ctx);

    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
    scanner.scan("bogus.pkg");

    cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
  }
View Full Code Here

  public void annotationConfigWAC() {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();

    ctx.scan("does.not.matter");

    ContextLoaderListener cll = new ContextLoaderListener(ctx);
    cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
  }
View Full Code Here

        ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);

        servletContext.addListener(new ContextLoaderListener(rootContext));
    }
View Full Code Here

TOP

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

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.