1

我正在使用 Spring-WS 1.5。我的 spring-servlet.xml 中有以下配置。

<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"
  xmlns:sws="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                                                 
  http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.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.test.mypackage"/>

  <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <constructor-arg ref="jaxbmarshaller"/>
  </bean>

  <bean id="jaxbmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
                <list>
                        <value>com.test.myclass1</value>
                        <value>com.test.myclass2</value>
                </list>
        </property>
  </bean>

  <bean id="endpointMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    <property name="interceptors">
            <list>
                <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
            </list>
    </property>
  </bean>

</beans>

“GenericMarshallingMethodEndpointAdapter”正在解组请求并使用此配置编组响应并按预期工作。但是,我想在我的端点方法处理程序中编组请求并希望访问编组器。如何访问编组器。我是否可以访问提供给 GenericMarshallingMethodEndpointAdapter 的那个。

@Endpoint
public class MyEndpoint {

        private static final String NAMESPACE_URI =  "http://www.test.org/9";

        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "RequestData")
        public JAXBElement<ResponseType> myEndpointHandler(JAXBElement<RequestType> request) {
            /* how do I access the marshaller here to marshal the request */
         }
}
4

1 回答 1

0

您可以自动装配它:

@Service
public class MarshallingServiceImpl implements MarshallingService{

    @Autowired
    private Jaxb2Marshaller jaxbmarshaller;

    @Override
    public String marshal(Entity entity) {
        StringResult marshalled = new StringResult();
        jaxbmarshaller.marshal(entity, marshalled);
        return marshalled.toString();
    }

}
于 2012-09-24T07:26:06.883 回答