Spring @Autowired is not working for @WebService a

2019-06-04 18:32发布

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.

1条回答
地球回转人心会变
2楼-- · 2019-06-04 19:16

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

查看更多
登录 后发表回答