如何使@WebService春天知道 [英] How to make an @WebService spring aware

查看:63
本文介绍了如何使@WebService春天知道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务,正在尝试将变量自动连接到其中.这是课程:

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

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

}

但是,当我尝试访问Web服务时,我得到的是Fail版本,这意味着未自动连接upgradeController.这是我的applicationContext:

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:

<?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类能够识别弹簧并自动装配

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

推荐答案

如果要进行自动装配, ProductRulesWebService 需要扩展 SpringBeanAutowiringSupport

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

扩展该类将允许自动连接 UpgradeController

Extending that class will allow UpgradeController to be autowired

这篇关于如何使@WebService春天知道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆