对您来说可能为时已晚,但是可以使用将 POJO 编组回 XML
final Result marshallerResult = new StringResult();
marshaller.marshal(input, marshallerResult);
marshaller
你用的那个在哪里wsTemplate
。
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.dhl.dctservice" />
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
</bean>
StringResult
来自org.springframework.xml.transform
包装。
要从 WSDL 生成 POJO,我使用的是 maven 插件
<!-- WSDL -> Java (start) -->
<plugin>
<!-- !!! READ !!! -->
<!-- mvn cxf-codegen-plugin:wsdl2java NOT working, comment phase and
run "mvn clean install -DskipTests") -->
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf-codegen-plugin.version}</version>
<executions>
<execution>
<id>wsdl2java</id>
<!-- comment this to generate java classes from wsdl during the "mvn
clean install -DskipTests" -->
<phase>manual-generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/service.wsdl</wsdl>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-b</extraarg>
<extraarg>${basedir}/src/main/resources/wsdl/bindings.xml</extraarg>
<extraarg>-client</extraarg>
<extraarg>-xjc-Xts</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>stax2-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-jaxb-xjc</artifactId>
<version>2.1.13</version>
</dependency>
</dependencies>
</plugin>
<!-- WSDL -> Java (end) -->
binding.xml
文件在哪里
<jaxb:bindings
version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings generateElementProperty="false">
<xjc:simple />
</jaxb:globalBindings>
</jaxb:bindings>