2011-02-18 79 views
7

我有一個Web服務,我正在嘗試自動裝入一個變量。這裏是類:如何使@WebService spring知道

package com.xetius.isales.pr7.service; 

import java.util.Arrays; 
import java.util.List; 

import javax.jws.WebService; 

import org.springframework.beans.factory.annotation.Autowired; 

import com.xetius.isales.pr7.domain.PR7Product; 
import com.xetius.isales.pr7.domain.PR7Upgrade; 
import com.xetius.isales.pr7.logic.UpgradeControllerInterface; 

@WebService(serviceName="ProductRulesService", 
      portName="ProductRulesPort", 
      endpointInterface="com.xetius.isales.pr7.service.ProductRulesWebService", 
      targetNamespace="http://pr7.isales.xetius.com") 
public class ProductRulesWebService implements ProductRulesWebServiceInterface { 

    @Autowired 
    private UpgradeControllerInterface upgradeController; 

    @Override 
    public List<PR7Product> getProducts() { 
     if (upgradeController == null) { 
      return Arrays.asList(new PR7Product("Fail")); 
     } 
     return upgradeController.getProducts(); 
    } 

    @Override 
    public List<PR7Upgrade> getUpgrades() { 
     if (upgradeController == null) { 
      return Arrays.asList(new PR7Upgrade("Fail")); 
     } 
     return upgradeController.getUpgrades(); 
    } 

    @Override 
    public List<PR7Product> getProductsForUpgradeWithName(String upgradeName) { 
     if (upgradeController == null) { 
      return Arrays.asList(new PR7Product("Fail")); 
     } 
     return getProductsForUpgradeWithName(upgradeName); 
    } 

} 

然而,當我嘗試訪問網絡服務我正在失敗的版本恢復,這意味着upgradeController沒有被自動裝配。這是我的applicationContext:

<?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:component-scan base-package="com.xetius.isales.pr7" /> 
    <context:annotation-config /> 

    <bean id="upgradeController" class="com.xetius.isales.pr7.logic.UpgradeController" /> 

</beans> 

如何讓這個在@WebService類是春天認識和自動裝配情況

回答

11

如果你想自動裝配的情況發生,ProductRulesWebService需要延長SpringBeanAutowiringSupport

擴展該類將使UpgradeController作爲自動連接

3

使用堆棧像CXF,它支持Spring natively,那麼你基本上可以這樣做這樣的:

<bean id="aService" class="com.xetius.isales.pr7.service.ProductRulesWebService " /> 

<jaxws:endpoint id="aServiceEndpoint" implementor="#aService" address="/aService" /> 
+0

這可以也可以使用Jersey完成:http://stackoverflow.com/questions/21104567/springjersey-transactional-annotation –

1

根據容器版本,甚至春節,此後你將有一個簡單的解決方案,以使您的WSDL,使用:

@PostConstruct 
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);