2013-03-21 16 views
9

Qualcuno può spiegarmi il seguente comportamento di CXF?Come escludere il metodo da CXF WebService - strano comportamento

devo semplice 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); 

} 

Voglio avere la mia methodToExclude interfaccia (per la primavera), ma io non voglio avere questo metodo nel file WSDL generato. Il codice sopra fa esattamente questo.

Ma quando aggiungo @WebService annotazione all'interfaccia ottengo l'errore:

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

Qualcuno può spiegare questo a me? Qual è la differenza? Inoltre non sono sicuro se funzionerà bene più tardi, ma non ho trovato il modo di escludere lo methodToExclude quando uso @WebService.

risposta

5

L'@ javax.jws.WebMethod (escludere = true) viene utilizzato sull'attuazione:

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

Non tiratevi includono il metodo methodToExclude nell'interfaccia:

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

    @WebMethod 
    String method2(String s); 

} 
+1

@Betlista non può permettersi di prendere methodToExclude dall'interfaccia di soddisfare primavera, tutto quello che deve fare è per includere '@WebMethod (exclude = true)' solo nell'implementazione. –

1

suo ritardo, ma Vorrei inserire la mia risposta.

  1. sbarazzarsi di tutti il ​​@WebMethod come sono opzionali e necessarie solo quando un metodo deve essere esclusa.

    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. Aggiungi @WebMethod (esclude = true) per interfacciarsi Attuazione solo

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