2

Getting null pointer while trying to autowire.

Creating a Web application and using following webservices:

WebServiceEndpoint.java

@WebService
@Component
public class ChannelMapWebServiceEndpoint {

   @Autowired
   ChannelMapWebService webservice;



   public ChannelMapInfo4[] getMaps() throws RemoteException {
     return this.webservice.getMaps();
   }    

}

ChannelMapsebserviceImpl.java

@Service
public class ChannelMapWebServiceImpl implements ChannelMapWebService {

   public ChannelMapInfo4[] getMaps() throws RemoteException {
     System.out.println("hi");
   }

}

application context.xml

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

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="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">

    <context:annotation-config />
    <context:component-scan base-package="ccad" />
    <context:component-scan base-package="channelmapwebservice" />



    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>/WEB-INF/jdbc.properties</value>
        </property>
    </bean>


    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>

    </bean>

</beans>

I am getting the autowired object webservice as null while trying to connect through SoapUI.

Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63
Fisher
  • 41
  • 1
  • 1
  • 5
  • possible duplicates: http://stackoverflow.com/questions/4287837/spring-autowired-not-working and http://stackoverflow.com/questions/5697470/spring-autowiring-not-working – herman Jul 10 '13 at 10:08
  • can you add the "package" line for both classes? – herman Jul 10 '13 at 10:11
  • possible duplicate of [How to make an @WebService spring aware](http://stackoverflow.com/questions/5041154/how-to-make-an-webservice-spring-aware) – herman Jul 10 '13 at 10:21

1 Answers1

3

The ChannelMapWebServiceEndpoint object serving your request class is not instantiated (and managed) by Spring, which is why Spring can't autowire any dependencies.

See the accepted answer for this question: How to make an @WebService spring aware

Community
  • 1
  • 1
herman
  • 11,740
  • 5
  • 47
  • 58
  • Thank you. I cannt use cxf in my case.i got it working when i extended SpringBeanAutowiringSupport .My now my service desciption gives me two more methonds processInjectionBasedOnCurrentContext and processInjectionBasedOnServletContext any way to get rid of that – Fisher Jul 10 '13 at 12:01
  • The accepted answer there uses SpringBeanAutowiringSupport, so please accept. To solve your other problem, override these methods (call super) and annotate with @WebMethod(exclude=true). – herman Jul 10 '13 at 19:53