2017-05-08 107 views
0

我已经尝试了许多不同的方法来让resteasy客户端为我工作,但我陷入了一个错误。 java.lang.LinkageError的:无法连结组织/ JBoss的/ RestEasy的/客户/ JAXRS /内部/ ClientConfiguration无法让resteasy客户端工作

这里是我使用的客户端

public void createIssue() { 
    issue = new Issue(); 
    ResteasyClient client = new ResteasyClientBuilder().build(); 
    ResteasyWebTarget target = client.target("api-being-posted-to"); 
    Response response = target.request().header("Authorization: ", "Basic Foo") 
      .post(Entity.entity(issueJson, "application/json")); 
} 

我可以POST和GET方法使用相同的数据,并且我尝试让客户端使用不同的数据并发布到不同的地方,并始终得到相同的错误。这里是我的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>org.foo.bar</groupId> 
<artifactId>foo</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>war</packaging> 
<name>example</name> 

<dependencies> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxrs</artifactId> 
     <version>3.1.0.Final</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-client</artifactId> 
     <version>3.1.0.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>jaxrs-api</artifactId> 
     <version>3.0.8.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jackson-provider</artifactId> 
     <version>3.1.0.Final</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.3</version> 
     </plugin> 
    </plugins> 
</build> 

,这里是我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0"> 

<servlet-mapping> 
    <servlet-name>resteasy-servlet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

<context-param> 
    <param-name>resteasy.scan</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>resteasy.servlet.mapping.prefix</param-name> 
    <param-value>/rest</param-value> 
</context-param> 

<listener> 
    <listener-class> 
     org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap 
     </listener-class> 
</listener> 

<servlet> 
    <servlet-name>resteasy-servlet</servlet-name> 
    <servlet-class> 
     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher 
    </servlet-class> 
</servlet> 

我使用JBoss EAP 6.4是否有帮助。

回答

0
  1. 至于我可以告诉RestEasy的中的JBoss EAP 6.4所提供的版本是3.0.21.Final而不是3.1.0.Final但你可能修改了(见https://developer.jboss.org/thread/262213仅供参考)。

  2. 您使用不同的版本和不同的范围为您的resteasy库(3.0.8.Final为jaxrs-api),但这可能仍然可以。我会一直推荐使用Resteasy Proxy Framework。这可能是一个有点代码来写,但使事情总容易和清晰:

定义一个接口:

public interface IssueIF 
{ 
    @POST 
    @Path("/issue") 
    @Produces("text/plain") 
    Issue postIssue(Issue i); 
} 

使用它:

ResteasyClient client = new ResteasyClientBuilder().build(); 
ResteasyWebTarget target = client.target("http://example.com/base/uri"); 

SimpleClient simple = target.proxy(IssueIF.class); 
Issue issue = new Issue(); 
client.postIssue(issue); 

我没编译这段代码大部分是从文档复制/粘贴的,但它应该接近你所需要的。

编辑:

docs

Subclasses of LinkageError indicate that a class has some dependency on another class; however, the latter class has incompatibly changed after the compilation of the former class.

这表明,你有你使用编译和运行时使见上在没有1.

不同的库版本中的问题特别是如果你使用不同的范围,那么编译和运行时的版本是相同的!所以试着找出你的JBoss所提供的版本,并只使用这些版本。还要找出你提供了哪些引用的库,并用提供的范围标记它们。

+0

不幸的是我仍然收到同样的错误。 – GhostDonkeys

+0

你尝试了什么? – martinw