繁体   English   中英

如何从CXF WebService中排除方法 - 奇怪的行为

[英]How to exclude method from CXF WebService - strange behavior

有人可以向我解释一下CXF的以下行为吗?

我有简单的WebService:

import javax.jws.WebMethod;

public interface MyWebService {

    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

    @WebMethod(exclude = true)
    String methodToExclude(String s);

}

我想在接口(对于Spring)中使用我的methodToExclude ,但我不想在生成的WSDL文件中使用此方法。 上面的代码确实如此。

但是当我向界面添加@WebService注释时,我得到错误:

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface MyWebService {

    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

    @WebMethod(exclude = true)
    String methodToExclude(String s);

}

org.apache.cxf.jaxws.JaxWsConfigurationException:@ javax.jws.WebMethod(exclude = true)不能在服务端点接口上使用。 方法:methodToExclude

谁可以给我解释一下这个? 有什么不同? 另外我不确定它以后是否能正常工作,但是当我使用@WebService时,我没有找到如何排除methodToExclude的方法。

@ javax.jws.WebMethod(exclude = true)用于实现:

public class MyWebServiceImpl implements MyWebService {
    ...
    @WebMethod(exclude = true)
    String methodToExclude(String s) {
        // your code
    }
}

不要在接口中包含方法methodToExclude:

@WebService
public interface MyWebService {
    @WebMethod
    String method1(String s);

    @WebMethod
    String method2(String s);

}

它迟到但我想填写我的答案。

  1. 摆脱所有@WebMethod,因为它们是可选的,只有在必须排除方法时才需要。

     import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface MyWebService { String method1(String s); String method2(String s); String methodToExclude(String s); } 
  2. 仅将@WebMethod(exclude = true)添加到Interface Implementation

     public class MyWebServiceImpl implements MyWebService { String method1(String s) { // ... } String method2(String s) { // ... } @WebMethod(exclude = true) String methodToExclude(String s) { // ... } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM