线程" main"中的例外情况java.lang.NoSuchMethodError:org.jboss.resteasy.util.CaseInsensitiveMap.add(Ljava / lang / String; Ljava / lang / Object;)V

时间:2015-04-30 09:24:30

标签: java web-services rest jboss resteasy

我是RestEasy网络服务的新手。我从restEasy Web-Serivce得到了正确的回复,但当我尝试编写一个Web服务客户端时,我发现错误。请找到如下代码。 请告诉我问题在哪里。 我正在使用RestEasy 3.0.9 Final。

RestServiceClient.java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

public class RestServiceClient {

public static void main(String[] args) throws Exception {
    Client client = ClientBuilder.newBuilder().build();
    WebTarget target = client.target("http://localhost:8888/RestSpring/rest/response/hello");
    Response response = target.request().get();
    String value = response.readEntity(String.class);
    System.out.println("Response Value : "+value);
    response.close(); 
   }

}

的pom.xml

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java-version>1.7</java-version>
        <spring.version>4.0.5.RELEASE</spring.version>
        <resteasy.version>3.0.9.Final</resteasy.version>
        <jax.rs.version>2.0</jax.rs.version>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <jackson.version>1.9.4</jackson.version>
    </properties>


    <dependencies>
      <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency> 

        <!-- RestEasy  -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>${resteasy.version}</version>
        </dependency>

        <!-- RestEasy Spring Integration -->
        <dependency> 
            <groupId>org.jboss.resteasy</groupId> 
            <artifactId>resteasy-spring</artifactId> 
            <version>${resteasy.version}</version>
        </dependency>

        <!-- restEasy for file upload -->
        <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>2.2.0.GA</version>
       </dependency>

        <!-- RestEasy Jackson Json Mapper -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>${resteasy.version}</version>
        </dependency>

        <!-- JAX-RS -->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>${jax.rs.version}</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Log4j Jar -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Apache Common Lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>

        <!-- Junit and Mockito -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <!-- RestEasy Client -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>3.0.2.Final</version>
    </dependency>

    </dependencies>

RestService.java

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
import org.springframework.stereotype.Controller;

import com.web.app.rest.object.Employee;
import com.web.app.rest.object.FileUploadForm;

@Controller
@Path("/response")
public class RestService {

    @GET
    @Path("/hello")
    public String sayHelloRestEasy(){
        System.out.println("Calling web!");
        return "RestEasy say Hello user!!!";


    }
}

2 个答案:

答案 0 :(得分:2)

尝试使用相应版本的resteasy-multipart-provider:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-multipart-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>

2.2.0似乎很老了

答案 1 :(得分:0)

更改版本后,删除了javax.ws.rs-api jar从服务器获取响应。 这是配置文件,如下所示。

的pom.xml

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java-version>1.7</java-version>
        <spring.version>4.0.5.RELEASE</spring.version>
        <resteasy.version>3.0.9.Final</resteasy.version>
        <jax.rs.version>2.0</jax.rs.version>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <jackson.version>1.9.4</jackson.version>
    </properties>


    <dependencies>
      <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency> 

        <!-- RestEasy  -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>${resteasy.version}</version>
        </dependency>

        <!-- RestEasy Spring Integration -->
        <dependency> 
            <groupId>org.jboss.resteasy</groupId> 
            <artifactId>resteasy-spring</artifactId> 
            <version>${resteasy.version}</version>
        </dependency>

        <!-- restEasy for file upload -->
         <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>${resteasy.version}</version>
          </dependency>

        <!-- RestEasy Jackson Json Mapper -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
            <version>${resteasy.version}</version>
        </dependency>

        <!-- JAX-RS -->
        <!-- 
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>${jax.rs.version}</version>
        </dependency>
         -->
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Log4j Jar -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Apache Common Lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>

        <!-- Junit and Mockito -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <!-- RestEasy Client -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-client</artifactId>
        <version>${resteasy.version}</version>
    </dependency>

    </dependencies>

web.xml

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

    <listener> 
        <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class> 
    </listener> 

    <servlet> 
        <servlet-name>Resteasy</servlet-name> 
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> 
        <load-on-startup>1</load-on-startup>
    </servlet>

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

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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </context-param>