Announcement Announcement Module
Collapse
No announcement yet.
Random closing WebApplicationContex errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random closing WebApplicationContex errors

    Hi,

    From time to time we are getting the following info in the WLS logs
    Code:
    ####<Aug 28, 2007 11:19:15 AM CEST> <Info> <ServletContext-/admfenix>  <AdminServer> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <118829
    2755910> <BEA-000000> <Closing Spring root WebApplicationContext> 
    ####<Aug 28, 2007 11:19:16 AM CEST> <Warning> <HTTP> <AdminServer> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1188292756046> <BEA-101
    162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present -
     check whether you have multiple ContextLoader* definitions in your web.xml!.
    java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:170)
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
            at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:458)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(Unknown Source)....
    And later
    Code:
    ####<Aug 28, 2007 11:19:17 AM CEST> <Error> <HTTP> <AdminServer> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1188292757715> <BEA-1010
    17> <[weblogic.servlet.internal.WebAppServletContext@1670fa5 - appName: '_appsdir_fenix_ear', name: 'admfenix', context-path: '/admfenix'] Root cause of ServletException.
    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
            at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:121)
            at org.springframework.context.support.AbstractApplicationContext.getInternalParentBeanFactory(AbstractApplicationContext.java:915)
            at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:144)
    We are really puzzled about this. We don't know why the Spring context is being closed or who is ordering it? Any clues? IIRC everything started happening when some nested tag files (no Spring code inside) where deployed...but it may not have anything to do with them...

    Regards,

  • #2
    There is probably something weird (or messy) going on in your application. It seems as if another thread is trying to (re)create the root application context. Do you anywhere in your application create a new ApplicationContext?

    Comment


    • #3
      The global application context is loaded by a listener, there's one for the dispatcher-servlet and one more loader for the MDBs (this should just refer to the root context). It always happens when processing http requests.

      Regards,

      Comment


      • #4
        So you have multiple loaders, listeners and a servlet.xml... Can you post your web.xml and any other needed configuration files?

        Comment


        • #5
          WEB.XML:
          Code:
          <context-param>
             <param-name>locatorFactorySelector</param-name>
              <param-value>framework/mainContext.xml</param-value>
           </context-param>
          
           <context-param>
              <param-name>parentContextKey</param-name>
              <param-value>mainApplicationContext</param-value>
          </context-param>
          
          <listener>
             <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          
          <servlet>
             <servlet-name>dispatcher</servlet-name>
             <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
          </servlet>
          
          <servlet-mapping>
             <servlet-name>dispatcher</servlet-name>
             <url-pattern>/mvc/*</url-pattern>
          </servlet-mapping>
          MDB loader
          Code:
          @PostConstruct    
          private void init(){
             beanFactoryLocator = ContextSingletonBeanFactoryLocator.getInstance("classpath*:framework/mainContext.xml");
             beanFactoryReference = beanFactoryLocator.useBeanFactory("mainApplicationContext");    	
             WeakReferenceMonitor.monitor(this, new BeanFactoryReferenceReleaseListener(beanFactoryReference));
          }    
              
          private static class BeanFactoryReferenceReleaseListener implements WeakReferenceMonitor.ReleaseListener {
             private final BeanFactoryReference beanFactoryReference;
             public BeanFactoryReferenceReleaseListener(BeanFactoryReference beanFactoryReference) {
                this.beanFactoryReference = beanFactoryReference;
             }
             public void released() {
                this.beanFactoryReference.release();
             }
          }
          I can't post the dispatcher-servlet.xml (or the other XML files) as they are huge but they just define beans. Can you spot anything wrong?

          Comment


          • #6
            Check your packaged application (EAR, WAR), not to contain multiple references to the same classes: for example EAR pointing to a jar containing your application core classes and, also, the WAR lib folder containing the same jar with core classes.

            Comment


            • #7
              Thank you for the suggestion. I just checked it and everything seems normal. The common classes are packaged in the lib dir of the EAR. Any more ideas?

              Comment


              • #8
                Us too!

                We are also getting this error!!! We have a VERY similar configuration. We are using WLS 9.2 and Spring 2.0.1.

                We are seeing the problem in development environments, using an exploded deployment with hot deploy enabled.

                We can cause the error by simply updating a servlet (causing it to be hot deployed by WLS). When we access the serlvet after the hot deployment we get the same error message as you do.

                It has been our theory that the ContextLoaderListener is being "recreated" due to the hot deploy it does not properly clear the ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE from the ServletContext.

                We can provide more details if that would help.

                Thanks!

                Comment


                • #9
                  The common factor here is in my opinion WLS...

                  I do a lot of hot redeployment on Tomcat and Jetty without those errors. It might be due to some implementation in WLS that something 'hangs' around. Maybe there is some info on the WLS forums (are there any?).

                  Maybe create a JIRA for this, to keep it tracking and to get the attention of the core spring developers (and maybe BEA).

                  Comment


                  • #10
                    Thank you for reporting. I've raised a Jira issue (http://opensource.atlassian.com/proj...rowse/SPR-3821). Please provide as much information as you can there. It has to be easily solved once we can determine the root cause.

                    Regards,

                    Comment


                    • #11
                      Thanks

                      Thanks for creating the JIRA entry.

                      My co-worker and I were reading and stepping through the Spring code to try to locate the line of code that clears the ServletContext of the ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE attribute. I'll be darned if I can find it.

                      Anyone know where this takes place?

                      Comment


                      • #12
                        Well you can search and search but aren't going to find it.

                        It should be cleared by your servlet container as soons as the servlet dies/reloads. That's also why I think that it hangs around in WLS that it doesn't get released properly.

                        Comment


                        • #13
                          Ah

                          I see! I guess I'll stop looking now Thank you.

                          I'm dreading the fact that this appears to be a WLS issue. BEA's recent track record with fixing reported bugs in their product *in my experience* (7 years now) is extremely poor.

                          One workaround -- I found that the problem disappears if I use ContextLoaderServlet instead of ContextLoaderListener. I'm using Acegi too, so I also had to set the init-param named "init" to "lazy". This is going to be my workaround of choice for the time being, unless there's some other issues with using the servlet vs the listener that I'm not aware of?
                          Last edited by jlindwall; Aug 30th, 2007, 04:19 PM. Reason: typo

                          Comment


                          • #14
                            That's really strange because the do exactly the same... So it must be something due to unregistering Listeners and there resources.

                            Comment


                            • #15
                              Thank you for the workaround. It worked. It forced me to change Hibernate cache provider to OSCache though because EHCache started complaining soon after redeploying.

                              Regards,

                              Comment

                              Working...
                              X