2013-07-10 84 views
1

嘗試自動裝配時獲取空指針。Spring @Autowired不適用於@WebService註釋類

創建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。

+0

可能的重複:http://stackoverflow.com/questions/4287837/spring-autowired-not-working和http://stackoverflow.com/questions/ 5697470/spring-autowiring-not-working – herman

+0

你能爲這兩個類添加「包」行嗎? – herman

+0

可能的重複[如何使@WebService春意識](http://stackoverflow.com/questions/5041154/how-to-make-an-webservice-spring-aware) – herman

回答

2

爲你的請求類服務的ChannelMapWebServiceEndpoint對象沒有被Spring實例化(和託管),這就是Spring不能自動調用任何依賴關係的原因。

見接受的答案對這個問題: How to make an @WebService spring aware

+0

謝謝。 我不能使用cxf在我的case.i得到它的工作,當我擴展SpringBeanAutowiringSupport。現在我的服務desciption給了我兩個methonds processInjectionBasedOnCurrentContext和processInjectionBasedOnServletContext任何方式擺脫那 – Fisher

+0

那裏接受的答案使用SpringBeanAutowiringSupport,所以請接受。要解決您的其他問題,請覆蓋這些方法(調用super)並使用@WebMethod(exclude = true)進行註釋。 – herman

相關問題