简体   繁体   中英

How to exclude method from CXF WebService - strange behavior

Can someone explain to me the following behavior of CXF?

I have simple 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);

}

I want to have my methodToExclude in interface (for Spring), but I do not want to have this method in generated WSDL file. The code above does exactly that.

But when I add @WebService annotation to the interface I get error:

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: The @javax.jws.WebMethod(exclude=true) cannot be used on a service endpoint interface. Method: methodToExclude

Can someone explain this to me? What's the difference? Also I'm not sure if it will work fine later, but I didn't find the way how to exclude the methodToExclude when I use @WebService .

The @javax.jws.WebMethod(exclude=true) is used on the implementation:

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

Don´t include the method methodToExclude in the interface:

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

    @WebMethod
    String method2(String s);

}

Its late but I would like to chip in my answer.

  1. Get rid of all the @WebMethod as they are optional and needed only when a method must be excluded.

     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. Add @WebMethod(exclude = true) to Interface Implementation only

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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