upgrade jaxws-rt 2.2.1 to 2.2.10 with SpringBeanAutowiringSupport

Recently I did an upgrade of my webapp which was using jaxws-rt version 2.2.1 to the currently latest version which is 2.2.10.  Here I am listing the issues that I faced while upgrade.

Versions

  1. Java 7
  2. apache-tomcat-7.0.57
  3. spring- 3.1.1.RELEASE
  4. jaxws-rt-2.1.1

Webservice

When I tried to updgrade the jaxws-rt, I had issues with spring @Autowired not working in the webservice. Here is one sample webservice

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;


@WebService
public class Hello extends SpringBeanAutowiringSupport{

	@Autowired	
	private MyTestComponent testComponent;
	
	@WebMethod
	public String sayHello() {
		testComponent.sayHello();
		return "Hello";
	}
}

After the upgrade testComponent always used to return null and testComponent.sayHello() always used to throw NUllPointerException.

Web.xml

After searching for the solution I got to this issue,  JAX-WS and SpringBeanAutowiringSupport don’t work on Tomcat 7 .

So the workaround for this issue was to introduce  <absolute-ordering/> in web.xml. So here is how my web.xml looked after the change.

<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="testws" version="3.0">
 	<!-- workaround for spring not being correctly initialized after jaxws-rt upgrade -->
	<absolute-ordering/>
		
	<!-- persistence Webservice -->
	 <listener>
	   <listener-class>
	        org.springframework.web.context.ContextLoaderListener
	   </listener-class>
	</listener> 
   
  <servlet>
    <servlet-name>HelloService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>HelloService</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>

</web-app>

After introducing the workaround the issue is solved. But I have started to get some memory leaks on redeploy. And this issue is probably the same as listed in Memory leak on ThreadLocalContainerResolver. For me restarting the tomcat is an option so I would expect that this issue is no longer existing in the next coming versions.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.