8 Replies Latest reply on Jun 1, 2012 12:55 PM by nnanda

    JBoss 7.1.1.Final issue with Spring 3.1.1

    nnanda

      Hi All,

       

      We are using Spring 3.1.1 and JBoss 7.1.1.Final for our web application. My web.xml looks like below:

       

      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          id="WebApp_ID" version="2.5">
      
          <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath:spring/applicationContext.xml</param-value>
          </context-param>
      
          <!-- Listeners are loaded in the sequence mentioned in web.xml -->
          <listener>
              <description>Spring Application Context listener. This must be loaded first</description>
              <display-name>Spring Context Config Listener</display-name>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          <listener>
              <description>JAX-WS Listener. This will initialize Metro web service engine</description>
              <display-name>JAX-WS Listener</display-name>
              <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
          </listener>
      
          <servlet>
              <servlet-name>JAX-WS Servlet</servlet-name>
              <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
              <load-on-startup>2</load-on-startup>
          </servlet>
      
          <servlet>
             <servlet-name>RESTful Servlet</servlet-name>
             <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
      
             <init-param>
                 <param-name>com.sun.ws.rest.config.property.resourceConfigClass</param-name>
                 <param-value>com.demo.util.ws.restful.config.DemoRestfulResourcesConfig</param-value>
             </init-param>
             <init-param>
                 <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
                 <param-value>com.demo.util.ws.handler.DemoRestfulRequestHandler</param-value>
             </init-param>
             <load-on-startup>3</load-on-startup>
          </servlet>
      
          <servlet-mapping>
              <servlet-name>JAX-WS Servlet</servlet-name>
              <url-pattern>/ws/*</url-pattern>
          </servlet-mapping>
      
          <servlet-mapping>
             <servlet-name>RESTful Servlet</servlet-name>
             <url-pattern>/restful/*</url-pattern>
          </servlet-mapping>
      
      </web-app>
      

       

      This clearly tells to load Spring context listener before Sun-Metro listener. However, JBoss 7 is loading Sun Metro servlet/listener before Spring context listener.

       

      This works perfectly fine in JBoss 5.1.

       

      Am I doing something wrong? Why JBoss 7 is behaving weirdly?

       

      Thanks,

      Niranjan

        • 1. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
          sfcoy

          Ordering of servlet listeners was only formalised in the Servlet 3.0 specification.

           

          You are using a Servlet 2.5 deployment descriptor.

          • 2. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
            nnanda

            Stephen, are you suggesting to make use of Servlet 3.0 XSD and namespace for this XML?

            • 3. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
              sfcoy

              Yes. If you see the same behaviour with that then there is definitely something wrong.

               

              If you happen to be packaged inside an EAR file then be sure to update your application.xml too.

              • 4. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
                nnanda

                Hi Stephen,

                 

                I tried putting Servlet 3.0 XSD/namespace; but that didn't help much. Here is what I tried:

                 

                My web.xml looks like below:

                 

                <?xml version="1.0" encoding="UTF-8"?>

                <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

                    version="3.0">

                 

                It still loads JAXWS Listener before Spring Listener.

                 

                Then I tried putting <absolute-ordering> in the web.xml. This tag expects names of the components that are defined in web.xml. But I do not know how to provide a name to a listener. So, this also didn't help me much.

                 

                The Spring and JBoss guys are perhaps not working in tandem and philophically different. Earlier I had faced below issues with Spring and JBoss 7.

                 

                1. Spring's classloading broke for the Native JDBC Extractor. I raiseda  JIRA and Spring guys fixed that in 3.1.1

                2. Spring's transaction manager (normal data source tx manager) does not coordinate properly with JBoss's data source manager. And, because of this, when I used declarative transaction in my app, Spring never released the DB connections.

                 

                Anyways, my real issue is: my application is a Sun-Metro app and the endpoint layer is outside Spring's bean pool. But, I need some spring beans inside my endpoint layer. So, what I did is, I created a SpringManager class which is application context aware (which means it has a reference to already created Spring bean pool) and then I get reference of spring beans through this class. Now what is happening, because Spring listener is getting loaded after jaxws listener, my calls to SpringManager.getBeanById() is returning NULL (obviously it is null because Spring is yet to get loaded).

                 

                Please provide any pointers you may have on this.

                 

                Thanks,

                Niranjan

                • 5. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
                  sfcoy

                  I think you have something else going on, because this works as advertised for me. Have you tried setting breakpoints in these classes?

                  • 6. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
                    pmm

                    Stephen Coy wrote:

                     

                    Ordering of servlet listeners was only formalised in the Servlet 3.0 specification.

                     

                    You are using a Servlet 2.5 deployment descriptor.

                     

                    According to the servlet expert group the version of the descriptor does not determine what  features from the container can and cannot be used.

                    • 7. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
                      sfcoy

                      Philippe Marschall wrote:

                       

                      Stephen Coy wrote:

                       

                      Ordering of servlet listeners was only formalised in the Servlet 3.0 specification.

                       

                      You are using a Servlet 2.5 deployment descriptor.

                       

                      According to the servlet expert group the version of the descriptor does not determine what  features from the container can and cannot be used.

                       

                      That thread looks more like an argument than a statement of fact. In any event the behavior at this time is not specified.

                      • 8. Re: JBoss 7.1.1.Final issue with Spring 3.1.1
                        nnanda

                        Essentially speaking, the web.xml version does not matter; if it is present, it will take priority over @WebServlet annotation. Am I correct?

                         

                        Stephen, I am still wondering if there is any way to know how the listener loading sequence is determined. Even I tried putting metadata-complete=true in the web.xml.

                         

                        Any more pointers? Or are you suggesting to close this thread?

                         

                        Thanks,

                        Niranjan