如何让@WebService知道Spring

时间:2022-03-21 04:57:34

I have a Web Service which I am trying to Autowire a variable into. Here is the class:

我有一个Web服务,我试图将变量自动装入。这是班级:

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

}

However, when I try to access the web service I am getting the Fail version returned, meaning that upgradeController is not being autowired. Here is my applicationContext:

但是,当我尝试访问Web服务时,我收到了Fail版本,这意味着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>

How do I make it so that the @WebService class is spring aware and autowiring happens

如何使@WebService类具有弹簧感知并自动装配发生

3 个解决方案

#1


11  

If you want autowiring to happen, ProductRulesWebService needs to extend SpringBeanAutowiringSupport

如果您希望自动装配发生,ProductRulesWebService需要扩展SpringBeanAutowiringSupport

Extending that class will allow UpgradeController to be autowired

扩展该类将允许UpgradeController自动装配

#2


3  

Use a stack like CXF, which supports Spring natively, then you can essentially do something like this:

使用像CXF这样的堆栈,它本身支持Spring,那么你基本上可以这样做:

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

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

#3


1  

Depending on container version or even the Spring, hereinafter you will have an easy solution to expose your WSDL, use:

根据容器版本甚至Spring,在下文中您将有一个简单的解决方案来公开您的WSDL,使用:

@PostConstruct
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

#1


11  

If you want autowiring to happen, ProductRulesWebService needs to extend SpringBeanAutowiringSupport

如果您希望自动装配发生,ProductRulesWebService需要扩展SpringBeanAutowiringSupport

Extending that class will allow UpgradeController to be autowired

扩展该类将允许UpgradeController自动装配

#2


3  

Use a stack like CXF, which supports Spring natively, then you can essentially do something like this:

使用像CXF这样的堆栈,它本身支持Spring,那么你基本上可以这样做:

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

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

#3


1  

Depending on container version or even the Spring, hereinafter you will have an easy solution to expose your WSDL, use:

根据容器版本甚至Spring,在下文中您将有一个简单的解决方案来公开您的WSDL,使用:

@PostConstruct
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);