【问题标题】:wsgen exposes methods that are not annotated with @WebMethodwsgen 公开未使用 @WebMethod 注释的方法
【发布时间】:2016-03-15 14:57:29
【问题描述】:

我定义了以下最小网络服务:

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 注释:putDatadoSomething。 但是在运行 wsgen 时,它会生成一个包含 myInternalMethod 的 WSDL,尽管它没有被 注释。

我这里有错误的配置吗?为什么暴露了一个没有@WebMethod注解的方法?

【问题讨论】:

    标签: java web-services wsdl webmethod


    【解决方案1】:

    好的,我找到了。默认情况下 all 公开方法。要排除一种方法,必须使用@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");
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多