无法使用 cxf-java2ws-plugin 生成正确的 wsdl
我正在尝试从 MyWebService 接口生成 wsdl 文件;
public interface MyWebService{
public ResponseMessage processService(MyWSData myWSData);
}
这是 java 类
public class MyWSData extends Message {
private String myString;
private MyOtherClass[] myOtherClassArray;
private Long myLong;
}
public class MyOtherClass{
private Long id;
private String name;
}
pom.xml 文件
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>2.4.3</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>com.ferdisonmezay.webservice.MyWebService</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<genClient>false</genClient>
<serviceName>MyWebService</serviceName>
<targetNameSpace>some-namespace-here</targetNameSpace>
<argline> -createxsdimports </argline>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
,这是我生成的 wsdl 文件中的 : MyOtherClass 数组字段看起来为空,
<xs:complexType name="myOtherClassArray">
<xs:sequence/>
</xs:complexType>
应该是什么原因,或者是否有其他方法可以生成正确的 wsdl 文件,包括 MyOtherClass[]
I'm trying to generate a wsdl file from MyWebService interface;
public interface MyWebService{
public ResponseMessage processService(MyWSData myWSData);
}
and here's the java classes
public class MyWSData extends Message {
private String myString;
private MyOtherClass[] myOtherClassArray;
private Long myLong;
}
public class MyOtherClass{
private Long id;
private String name;
}
and here is my pom.xml file
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>2.4.3</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>com.ferdisonmezay.webservice.MyWebService</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<genClient>false</genClient>
<serviceName>MyWebService</serviceName>
<targetNameSpace>some-namespace-here</targetNameSpace>
<argline> -createxsdimports </argline>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
in my generated wsdl file:
MyOtherClass array field looks empty
<xs:complexType name="myOtherClassArray">
<xs:sequence/>
</xs:complexType>
what should be the reason, or is there any other way to generate a correct wsdl file including MyOtherClass[]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个非常旧的 CXF 版本。
如果没有访问器,JAX-B 就无法对 MyOtherClass 执行任何操作。尝试向字段添加公共 getter 和 setter。
That's a very old version of CXF.
Without accessors, JAX-B can't do anything with MyOtherClass. Try adding public getters and setters to the fields.
有两件事:
CXF 2.5.2 java2ws 不喜欢从接口生成,因为它需要一个实现来在生成的服务器中实例化。因此,从实现接口的类生成。
实现 MyWebService 的类需要用 @javax.jws.WebService 进行注释,并且该类中的方法 processService() 需要用 @javax.jws.WebMethod 进行注释 - java2ws 只会为您的方法生成 WSDL想要它。您当然可以使用 import javax.jws.WebService; 实现MyWebService的类需要用
Two things:
CXF 2.5.2 java2ws doesn't like generating from interfaces, because it needs an implementation to instantiate in the generated server. So generate from a class that implements your interface.
The class that implements MyWebService needs to be annotated with @javax.jws.WebService, and the method processService() in that class needs to be annotated with @javax.jws.WebMethod - java2ws will only generate WSDL for the methods you want it to. You can of course use import javax.jws.WebService; and just annotate with @WebService, etc.