我在将Web服务映射到Java POJO时遇到问题,因为它包含两个元素:
label1
label_1
当插件将其转换为java POJO时,名称中的下划线将被剥离,从而导致生成的类中出现重复字段。
生成code.Location时出现[ERROR]错误 文件:/ C:/PrivateWS/test-project/sources/target/wsdl/test.wsdl {12,94}]。 com.sun.istack.SAXParseException2;的systenId: 文件:/ C:/PrivateWS/test-project/sources/target/wsdl/test.wsdl; lineNumber:12; columnNumber:94;两个声明导致冲突 在ObjectFactory类中。
我尝试使用外部绑定文件将其中一个元素重命名为其他名称,但这会失败。 我看了很多不同的论坛,但我找不到任何似乎有用的解决方案。据我所知,该属性不是已知的,这会导致跟随错误。
[ERROR]解析模式时出错。位置[ 文件:/ C:/PrivateWS/test-project/sources/target/classes/bindings.xjb {9,46}]。 com.sun.istack.SAXParseException2;的systenId: 文件:/ C:/PrivateWS/test-project/sources/target/classes/bindings.xjb; lineNumber:9; columnNumber:46;编译器无法兑现这一点 物业定制。它附着在一个错误的地方或它的地方 与其他绑定不一致。
如果让字段的重命名有效,我做错了什么?
更改wsdl不是一个选项,因为它是第三方wsdl。
的pom.xml
<?xml version="1.0"?><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testproject</groupId>
<artifactId>testproject</artifactId>
<version>0.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-binding-file</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>bindings.xjb</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-wsdl-file</id>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/wsdl</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources/wsdl</directory>
<includes>
<include>test.wsdl</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>TestProject</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generatePackage>com.testproject</generatePackage>
<schemaIncludes>
<schemaInclude>wsdl/test.wsdl</schemaInclude>
</schemaIncludes>
</configuration>
</execution>
</executions>
<configuration>
<bindingDirectory>${project.build.outputDirectory}</bindingDirectory>
<bindingIncludes>
<include>bindings.xjb</include>
</bindingIncludes>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>${project.build.directory}</schemaDirectory>
</configuration>
</plugin>
</plugins>
</build>
test.wsdl
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:schema xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" elementFormDefault="unqualified" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl" version="1.0">
<xsd:element name="requestType" type="tns:requestType"/>
<xsd:complexType final="extension restriction" name="requestType">
<xsd:sequence>
<xsd:element form="qualified" minOccurs="0" name="label1" type="xsd:string"/>
<xsd:element form="qualified" minOccurs="0" name="label_1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<message name="SayHelloRequest">
<part element="tns:requestType" name="parameters"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/"/>
</port>
</service>
binding.xjb
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings schemaLocation="*">
<jxb:bindings node="//xs:complexType[@name='requestType']" required="false">
<jxb:bindings node=".//xs:element[@name='label_1']" required="false">
<jxb:property name="label2"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
答案 0 :(得分:1)
您是否设置了underscoreBinding
并尝试了?
<jxb:bindings schemaLocation="*">
<jxb:globalBindings underscoreBinding="asCharInWord" />
</jxb:bindings>