CXF3.1-java.lang.AbstractMethodError

时间:2016-09-25 10:03:34

标签: java web-services cxf

以下是我的代码,我是新的CXF。这给出了错误。如何解决这个问题?

我的代码: -

String username = "myusername";
    String password = "myPassword";

    String usernameAndPassword = username + ":" + password;
    String authorizationHeaderName = "Authorization";
    String authorizationHeaderValue = "Basic " + java.util.Base64.getEncoder().encodeToString( usernameAndPassword.getBytes() );

    // Build the form for a post request
    MultivaluedMap< String, String> formParameters = new MultivaluedHashMap();
    formParameters.add( "field1", "fieldValue1" );
    formParameters.add( "field2", "fieldValue2" );

    // Perform a post request
    String restResource = "https://restserver:8080/app-name/rest-api/";
    Client client = ClientBuilder.newClient();
    Response res = client.target( restResource )
        .path( "login" ) // API Module Path
        .request( "application/json" ) // Expected response mime type
        .header( authorizationHeaderName, authorizationHeaderValue ) // The basic authentication header goes here
        .post( Entity.form( formParameters ) );  

以下是错误: -

Exception in thread "main" java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.path(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.path(ClientImpl.java:364)
at org.ymd.CxfClient.main(CxfClient.java:35)

我的依赖项: -

  • cxf-rt-rs-client-3.1.7.jar
  • cxf-rt-transports-http-hc-3.1.7.jar
  • cxf-bundle-jaxrs-2.1.2.jar
  • cxf-rt-frontend-jaxrs-3.1.7.jar
  • cxf-core-3.1.7.jar
  • cxf-rt-transports-http-3.1.7.jar
  • javax.persistence-2.1.1.jar -cxf-api-2.7.18.jar
  • javax.ws.rs-API-2.0.jar

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。这是因为版本冲突。当我使用maven获取依赖关系时,一切都得到了解决。