Announcement Announcement Module
Collapse
No announcement yet.
No WebApplicationContext found: no ContextLoaderListener registered? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No WebApplicationContext found: no ContextLoaderListener registered?

    I am working on an application that has used spring for a while to create
    remote proxies for EJBs and used acegi for security. I am starting to convert
    the struts to use DelegatingActionProxy. I have added the proper configuration
    to my struts-config.xml file and have added the bean definitions to my spring
    configuration. The good news is that the application is working well. The
    delegate passes the request to my action and the remote proxies are injected
    into the action. The bad news is that my MockStrutsTestCases are all failing
    with the following error:

    [ERROR,ContextLoaderPlugIn,main] Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/ClaimEmployeeList' defined in ServletContext resource [/WEB-INF/conf/claims-servlet.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.springframework.web.context.support.WebApplica tionContextUtils.getRequiredWebApplicationContext( WebApplicationContextUtils.java:83)
    at org.springframework.web.struts.DispatchActionSuppo rt.initWebApplicationContext(DispatchActionSupport .java:102)
    at org.springframework.web.struts.DispatchActionSuppo rt.setServlet(DispatchActionSupport.java:78)

    ...

    I do have ContextLoaderListener defined in my web.xml with a corresponding
    contextConfigLocation context-param. What have I missed?

    -Jeff

  • #2
    The MockStrutsTestCase simulates a servlet container but doesn't simulate it completely. It probably isn't simulating the loading of Listeners. I haven't used MockStrutsTestCase but I think you would need to extend it to handle the creation of the Spring application context.

    Comment


    • #3
      Originally posted by dgynn
      The MockStrutsTestCase simulates a servlet container but doesn't simulate it completely. It probably isn't simulating the loading of Listeners. I haven't used MockStrutsTestCase but I think you would need to extend it to handle the creation of the Spring application context.
      What would be the best way to create this context?

      Comment


      • #4
        Isssue resolved

        I resolved the issue by adding the following to my base test class setUp method:

        context.setInitParameter(ContextLoader.CONFIG_LOCA TION_PARAM,
        getContextDirectory() + SPRING_CONTEXT_FILE_LOCATION);
        new ContextLoader().initWebApplicationContext(context) ;


        I hope others find this useful.

        -Jeff

        Comment


        • #5
          Thank you!

          Thank you!

          You have saved me.. I've been banging my head against this desk for the past 2 hours.

          Comment


          • #6
            Originally posted by kuzman View Post
            I resolved the issue by adding the following to my base test class setUp method:

            context.setInitParameter(ContextLoader.CONFIG_LOCA TION_PARAM,
            getContextDirectory() + SPRING_CONTEXT_FILE_LOCATION);
            new ContextLoader().initWebApplicationContext(context) ;


            I hope others find this useful.

            -Jeff

            Having the same problem. Where should I put that context? where is the base test class setup method? sorry novice here.
            thanks

            Comment


            • #7
              I have the same problem using org.springframework.remoting.httpinvoker.HttpInvok erServiceExporter


              first I used this

              <listener>
              <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
              </listener>

              then I wanted to use spring mvc along my struts so I added the dispatcher servlet

              <servlet>
              <servlet-name>springmvc</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
              <load-on-startup>0</load-on-startup>
              </servlet>

              both needs their own configuration file, so I wanted to get rid of the contextloaderlistener
              but it doesn't seem dispatcher servlet is doing all the right initialisations for all the spring utility classes and beans

              I don't understand the point of the dispatcher servlet forcing it's own configuration file, it's very misleading

              Comment

              Working...
              X