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

Bet*_*sta 11 java cxf java-ws

有人可以向我解释一下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);

}
Run Code Online (Sandbox Code Playgroud)

我想拥有我的methodToExcludein接口(对于Spring),但我不想在生成的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);

}
Run Code Online (Sandbox Code Playgroud)

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

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

小智 7

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

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

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

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

    @WebMethod
    String method2(String s);

}
Run Code Online (Sandbox Code Playgroud)