为什么wsimport
不保留我的模型类的toString()
方法呢?所以我在我的Web服务中有这个模型类:
package webservice;
public class Book {
private String title;
private int pages;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
@Override
public String toString() {
return "Book [title=" + title + ", pages=" + pages + "]";
}
}
现在我想为WS客户机生成必要的工件:wsimport -keep http://localhost:8080/LibraryWs/BookWebServiceService?wsdl
并得到结果类:
package webservice;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for book complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="book">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="pages" type="{http://www.w3.org/2001/XMLSchema}int"/>
* <element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "book", propOrder = {
"pages",
"title"
})
public class Book {
protected int pages;
protected String title;
/**
* Gets the value of the pages property.
*
*/
public int getPages() {
return pages;
}
/**
* Sets the value of the pages property.
*
*/
public void setPages(int value) {
this.pages = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
}
所以没有toString:)我在哪里可以找到关于这个行为的规范,或者我如何让jax-ws在我的WSDL中显式地包含这个方法?谢谢。
1条答案
按热度按时间deikduxw1#
这实际上是一个愚蠢的问题,因为在WSDL中只有类成员变量被翻译,而不是方法。它们被编码为
complexType
。我想说,如果你想公开一个方法,它必须进入@WebService
,并(可选地)用@WebMethod
注解。否则,只有你的Web服务使用的类的属性才会进入WSDL。所以在http://localhost:8080/LibraryWs/BookWebServiceService?xsd=1
中,我们将有: