1

我配置了一个消息工厂 bean,如下所示:

<?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:ws="http://www.springframework.org/schema/web-services"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/web-services 
    http://www.springframework.org/schema/web-services/web-services-2.0.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="soapMessageFactory" class="javax.xml.soap.MessageFactory" factory-method="newInstance" />
    <bean id="saajMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
            <constructor-arg ref="soapMessageFactory" />
    </bean>

    <bean id="myService" class="com.mypackage.TestEndPoint">
        <property name="saajMessageFactory" ref="saajMessageFactory" />
    </bean> 



</beans>

TestEndpoint 类看起来像这样

@Endpoint
public class TestEndPoint {


    ObjectFactory objectFactory = new ObjectFactory();
    SaajSoapMessageFactory saajMessageFactory;


    @PayloadRoot(namespace="http://ws.mypackage.com", localPart="downloadSaajMessageRequest")
    @ResponsePayload
    public JAXBElement<DownloadResponseSaajType> invoke(@RequestPayload DownloadSaajMessageRequest req, MessageContext context ) throws Exception  {

        DownloadResponseSaajType response = new DownloadResponseSaajType();
        //DownloadResponseSaajType.PayLoad payload = new DownloadResponseSaajType.PayLoad();    

        DataHandler handler = new javax.activation.DataHandler(new FileDataSource("c:\\temp\\maven-feather.png"));

            SaajSoapMessage message = saajMessageFactory.createWebServiceMessage();
            message.addAttachment("picture", handler);
            message.addAttachment("picture", handler);

           //payload.setMessagePayLoad(handler);
            //response.setPayLoad(payload);

            response.setRequestName("NAMEOF");
            context.setResponse(message);
            return objectFactory.createDownloadSaajMessageResponse(response); 

    }

    public void setSaajMessageFactory(SaajSoapMessageFactory saajMessageFactory){
        this.saajMessageFactory = saajMessageFactory;
        }

        public SaajSoapMessageFactory getSaajMessageFactory(){
            return saajMessageFactory;
        }
}

我在尝试使端点工作时遇到了一些问题,当我尝试调试代码时,我发现 saajMessageFactory 从未初始化并且始终为空。我是否对配置做错了什么?

4

1 回答 1

1

您必须将 PayloadRootAnnotationMethodEndpointMapping bean 添加到您的配置 xml。

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>
于 2012-07-15T16:49:07.920 回答