简体   繁体   中英

Why is this spring bean not initialised? It is always null.

I have a message factory bean configured as shown below:

<?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>

The TestEndpoint class looks like this

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

I am having a few problems trying to get the endpoint to work and when i tried to debug the code i found that saajMessageFactory is never initialised and it is always null. Have i done something wrong with the configuration?

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

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM