以下是我的代码,我是新的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)
我的依赖项: -
答案 0 :(得分:0)
我解决了我的问题。这是因为版本冲突。当我使用maven获取依赖关系时,一切都得到了解决。