我定义了以下最小网络服务:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
@WebMethod
public void putData(final String value) {
System.out.println("value: "+value);
}
@WebMethod
public void doSomething() {
System.out.println("doing nothing");
}
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}
正如您所看到的,我有两个想要公开的方法,因为它们是用 @WebMethod
注释的:putData
和 doSomething
。
但是,当运行 wsgen 时,它会生成一个包含 myInternalMethod
的 WSDL,尽管它未被注释。
我这里配置有误吗?为什么暴露的方法没有用@WebMethod注释?
最佳答案
好的,我找到了。默认情况下,所有公共(public)方法都会公开。要排除某个方法,必须使用 @WebMethod(exclude=true)
对其进行注释。
这是一个相当奇怪的要求,因为这意味着我只需使用 @WebMethod
注释那些我不想公开的方法。
这是正确的代码:
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class DummyWS {
public static void main(String[] args) {
final String url= "http://localhost:8888/Dummy";
final Endpoint endpoint= Endpoint.create(new DummyWS());
endpoint.publish(url);
}
public void putData(final String value) {
System.out.println("value: "+value);
}
public void doSomething() {
System.out.println("doing nothing");
}
@WebMethod(exclude=true)
public void myInternalMethod() {
System.out.println("should not be exposed via WSDL");
}
}
关于java - wsgen 公开未使用 @WebMethod 注解的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36014797/