Java 如何从cxfwebservice中排除方法-奇怪的行为

Java 如何从cxfwebservice中排除方法-奇怪的行为,java,cxf,java-ws,Java,Cxf,Java Ws,有人能给我解释一下CXF的以下行为吗 我有一个简单的Web服务: 导入javax.jws.WebMethod; 公共接口MyWebService{ @网络方法 字符串方法1(字符串s); @网络方法 字符串方法2(字符串s); @WebMethod(exclude=true) 字符串方法排除(字符串s); } 我想在接口(对于Spring)中使用我的方法排除,但我不想在生成的WSDL文件中使用此方法。上面的代码正是这样做的 但是,当我向界面添加@WebService注释时,我得到了错误: 导入

有人能给我解释一下CXF的以下行为吗

我有一个简单的Web服务:

导入javax.jws.WebMethod;
公共接口MyWebService{
@网络方法
字符串方法1(字符串s);
@网络方法
字符串方法2(字符串s);
@WebMethod(exclude=true)
字符串方法排除(字符串s);
}
我想在接口(对于Spring)中使用我的
方法排除
,但我不想在生成的WSDL文件中使用此方法。上面的代码正是这样做的

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

导入javax.jws.WebMethod;
导入javax.jws.WebService;
@网络服务
公共接口MyWebService{
@网络方法
字符串方法1(字符串s);
@网络方法
字符串方法2(字符串s);
@WebMethod(exclude=true)
字符串方法排除(字符串s);
}
org.apache.cxf.jaxws.JaxWsConfigurationException:@javax.jws.WebMethod(exclude=true)不能在服务端点接口上使用。方法:方法排除

有人能给我解释一下吗?有什么区别?另外,我不确定它以后是否会正常工作,但我没有找到在使用
@WebService
时如何排除
方法的方法,在实现中使用了@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);

}

很晚了,但我想插嘴回答

  • 去掉所有的@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);
    
    }
    
  • 仅将@WebMethod(exclude=true)添加到接口实现

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

  • @Betlista无法从接口中删除methodToExclude来满足Spring的需求,他只需要在实现中包含
    @WebMethod(exclude=true)