title: JAX WS webservice does not take spring bean from applicationcontext, hence throws null pointer exception
body: <p>Hi I have got the webservice up and running , i have used jax ws. I have used Spring to be able to use beans with Autowired and stuff that spring gives like property value injection in applicationContext.xml. </p>
  
  <p>I have the below spring applicationcontext.xml entry:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.mybeans.service" /&gt;      
  &lt;bean  id="myProperty" class="com.mybeans.service.MyBeanProperty"
  p:Size="BIG"&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>In web service end point class , i have done:</p>
  
  <pre><code>@Autowired private MyBeanProperty myProperty;
  </code></pre>
  
  <p>And I have a method :</p>
  
  <pre><code>public String getSize() {
  
  return myProperty.getSize();
  
  }
  </code></pre>
  
  <p>Unfortunately when i invoke the method it does not get any value and throws nullpointerexception.</p>
  
  <p>PS: I used soapUI to run the wsdl of the webservice and invoked the method.</p>
  
  <p>Is the webservice runs before the beans get created by Spring??</p>
  
  <hr>
  
  <p>To duffmo</p>
  
  <p>Yes i used component scan in applicationContext. And i do have the context loader listener as below in web.xml. Please help me..                                      </p>
  
  <p>Here is my complete code explainaton with code</p>
  
  <p>I am using JAX-WS and Spring and try to setup a few WebServices which need run on Tomcat 7.
  I am using Maven as build tool therefore I just list my two dependencies here:</p>
  
  <pre><code>&lt;dependencies&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
        &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
        &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
     &lt;/dependency&gt;
  
       &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
        &lt;artifactId&gt;jaxws-rt&lt;/artifactId&gt;
        &lt;version&gt;2.1.3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>my service classes are located in com.test.services and are named TestService &amp; HelloWorldService and look as follows:</p>
  
  <pre><code>package com.test.services;
  
  import javax.jws.WebMethod;
  import javax.jws.WebService;
  
  @WebService( name = "Test", serviceName = "TestService" )
  public class TestService {
  
    @WebMethod
    public String getTest() {
      return "Test";
    }
  
  }
  </code></pre>
  
  <p>this is my web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" 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_2_5.xsd"&gt;
    &lt;display-name&gt;toolbox&lt;/display-name&gt;
    &lt;description&gt;testing webservices&lt;/description&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;com.sun.xml.ws.transport.http.servlet.WSServletContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.xml.ws.transport.http.servlet.WSServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/testservice&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/helloworldservice&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
      &lt;session-timeout&gt;10&lt;/session-timeout&gt;
    &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and this is my sun-jaxws.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'&gt;
      &lt;endpoint
          name="jaxws-servlet"
          implementation="com.test.services.TestService"
          url-pattern="/testservice"/&gt;
      &lt;endpoint
          name="jaxws-servlet"
          implementation="com.test.services.HelloWorldService"
          url-pattern="/helloworldservice" /&gt;
  &lt;/endpoints&gt;
  </code></pre>
  
  <p>This works great and I can access the services by pointing my browser to [url]<a href="http://localhost:8080/toolbox/testservice[/url]" rel="nofollow">http://localhost:8080/toolbox/testservice[/url]</a> respectively [url]<a href="http://localhost:8080/toolbox/helloworldservice[/url]" rel="nofollow">http://localhost:8080/toolbox/helloworldservice[/url]</a>.
  However Spring support is obviously not activated.</p>
  
  <p>I tried the following which just leaver the HelloWorldService available:
  web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" 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_2_5.xsd"&gt;
    &lt;display-name&gt;toolbox&lt;/display-name&gt;
    &lt;session-config&gt;
      &lt;session-timeout&gt;30&lt;/session-timeout&gt;
    &lt;/session-config&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and  applicationContext.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;
    &lt;context:component-scan base-package="com.test.services" /&gt;
    &lt;bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"&gt;
      &lt;property name="baseAddress" value="http://localhost:8080/" /&gt;
    &lt;/bean&gt;
   &lt;/beans&gt;
  </code></pre>
  
  <p>furthermore I annotated both Service classes with @Service annotation. As I mentioned before, this only publishes the alphabetically first webservice, hence HelloWorldService.
  Also it changes the URL, as the service is now available as [url]<a href="http://localhost:8080/[/url]" rel="nofollow">http://localhost:8080/[/url]</a> rather than [url]<a href="http://localhost:8080/toolbox/helloworldservice[/url]" rel="nofollow">http://localhost:8080/toolbox/helloworldservice[/url]</a>.
  The logging of Tomcat shows, that the Spring Context loads both Classes as Spring beans.
  Do you have any ideas or suggestions on how to enable Spring support while keeping both services available??</p>