Spring @Autowired不适用于@WebService注释类

时间:2013-07-10 09:51:56

标签: spring web-services dependency-injection

尝试自动装配时获取空指针。

创建Web应用程序并使用以下Web服务:

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");
   }

}

应用程序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>

尝试通过SoapUI进行连接时,我将自动对象webservice作为null。

1 个答案:

答案 0 :(得分:2)

Spring不会实例化(和管理)为您的请求类提供服务的ChannelMapWebServiceEndpoint对象,这就是为什么Spring无法自动装配任何依赖项的原因。

请参阅此问题的已接受答案: How to make an @WebService spring aware