Как сделать пружину @WebService осведомленной

У меня есть веб-служба, в которую я пытаюсь автоматически подключить переменную. Вот класс:

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

}

Однако, когда я пытаюсь получить доступ к веб-службе, мне возвращается версия Fail, что означает, что updateController не подключается автоматически. Вот мой контекст приложения:

<?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 знал о весне и происходило автоматическое подключение


person Xetius    schedule 18.02.2011    source источник


Ответы (3)


Если вы хотите, чтобы происходило автоматическое связывание, ProductRulesWebService необходимо расширить SpringBeanAutowiringSupport.

Расширение этого класса позволит автоматически подключать UpgradeController.

person jeffroel    schedule 18.02.2011

Используйте такой стек, как CXF, который поддерживает Spring изначально, то вы можете сделать что-то вроде этого:

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

<jaxws:endpoint id="aServiceEndpoint" implementor="#aService" address="/aService" />
person Biju Kunjummen    schedule 18.02.2011
comment
Это также можно сделать с помощью Джерси: stackoverflow.com/questions/21104567/ - person Constantino Cronemberger; 06.08.2014

В зависимости от версии контейнера или даже Spring, в дальнейшем у вас будет простое решение для раскрытия вашего WSDL, используйте:

@PostConstruct
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
person Tiago Medici    schedule 26.03.2016