2013-03-21 10 views
9

Czy ktoś może mi wyjaśnić następujące zachowanie CXF?Jak wykluczyć metodę z CXF WebService - dziwne zachowanie

Mam proste 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); 

} 

Chcę mieć mój methodToExclude interfejs (na wiosnę), ale nie chcę mieć tej metody w wygenerowanym pliku WSDL. Powyższy kod robi dokładnie to.

Ale kiedy dodać @WebService adnotacji do interfejsu otrzymuję błąd:

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

Czy ktoś może mi to wyjaśnić? Co za różnica? Również nie jestem pewien, czy to będzie działać dobrze później, ale nie znalazłem sposób, aby wykluczyć methodToExclude, gdy używam @WebService.

Odpowiedz

5

@ umieszczony javax.jws.WebMethod (wyklucza = prawda) jest stosowany w celu wykonania:

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

Do not obejmować methodToExclude metoda w Interface

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

    @WebMethod 
    String method2(String s); 

} 
+1

@Betlista nie może sobie pozwolić na wykupienie methodToExclude z interfejsu w celu zaspokojenia Spring, wszystko co musi zrobić, to włączyć '@WebMethod (exclude = true)' tylko w implementacji. –

1

późnego ale Chciałbym chip w mojej odpowiedzi.

  1. Pozbądź wszystkich @WebMethod jak są opcjonalne i potrzebne tylko wtedy, gdy metoda musi być wykluczone.

    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. Dodaj @WebMethod (wyklucza = true) interfejs implementacja tylko

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