Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

web services - How to make an @WebService spring aware

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

}

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>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Extending that class will allow UpgradeController to be autowired


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...