2 Replies Latest reply on Oct 18, 2011 9:44 PM by dbaeli

    Loading Order of ServletContextListener, Servlet & Portlet

    llengcai

      We are having problem when using Spring Portlet MVC within GateIn-JBoss (EPP 5.0 & GateIn 3.1.0-GA) when packaging the WAR into EAR file.

       

      From what I notice, the Portlet seems to be loaded first and only after that ServletContextListener is being loaded. This cause error to our application as the main applicationContext (for spring) contains the dependents bean which is required by the bean inside the portlet context. But in this case, the portlet context is loaded first, thus the it fails to find the bean which suppose to be loaded by the servlet context listener.

       

      Seems like the order is inconsistent for a few different scenarios. The loading order are as the followings:

       

      Scenario 1 - War File. Restart the JBoss application server

      1. ServletContextListener

      2. Portlet

       

      Scenario 2 - War File. Hotdeploy without restarting JBoss application server

      1. Portlet

      2. ServletContextListener

       

      Scenario 3 - EAR File. Hotdeploy without restarting JBoss application server

      1. Portlet

      2. ServletContextListener

       

      Scenario 4 - EAR File. Hotdeploy without restarting JBoss application server

      1. Portlet

      2. ServletContextListener

       

      I gone through the Portlet 2.0 specification, unfortunately it is silent about the loading order. Anyway, I would expect (and I believe most ppl too) that ServletContextListener is loaded first, follows by Servlet, and lastly Portlet.

       

      Does anyone have any idea what if this is the way it should work?

       

      Thank you!

        • 1. Re: Loading Order of ServletContextListener, Servlet & Portlet
          dbaeli

          Hello,

          Hot deploying a simple Spring MVC Sample in an EAR or WAR, behaves the same.

           

          On the server side logs with can see the WebApplicationContext is initialized too late in case of Portlet (and webapp being re-deployed).

           

          LOG Content

          ------------------------------------------

          16:01:43,031 INFO  [[/PortletEAR]] Destroying Spring FrameworkPortlet 'scorecard'

          16:01:43,031 WARN  [MainResourceResolver] Cannot find servlet context module

          16:01:43,041 INFO  [[/PortletEAR]] Closing Spring root WebApplicationContext

          16:01:43,081 INFO  [DeployHandler] End stop, [vfszip:/D:/newJBOSS/jboss-epp-5.1/jboss-as/server/default/deploy/SampleEAR.ear/]

          16:01:43,081 INFO  [DeployHandler] Begin start, [vfszip:/D:/newJBOSS/jboss-epp-5.1/jboss-as/server/default/deploy/SampleEAR.ear/]

          16:01:43,390 INFO  [TomcatDeployment] deploy, ctxPath=/Dummy

          16:01:44,592 INFO  [[/PortletEAR]] Initializing Spring FrameworkPortlet 'scorecard'

          16:01:44,612 ERROR [org.springframework.web.portlet.DispatcherPortlet] (ResourceContainer.invoker.nonDaemon-1) Context initialization failed

          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scoreCardController' defined in PortletContext resource [/WEB-INF/scorecard-portlet.xml]: Cannot resolve reference to bean 'scoreCardService' while setting bean property 'scoreCardService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'scoreCardService' is defined

                          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

                          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)

                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)

                          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)

          ....

          16:01:45,639 INFO  [[/PortletEAR]] Initializing Spring root WebApplicationContext

          --------------------------------------------

          • 2. Re: Loading Order of ServletContextListener, Servlet & Portlet
            dbaeli

            A test project (without Spring MVC) has been done to show that the init order is changing between normal startup and hotdeployment of wars.

            And an issue in the dedicated project has been opened :  https://issues.jboss.org/browse/GTNPC-76

             

            Hoping it will help to identify and fix the unconsistency in the deployment order.

             

            Thanks