简体   繁体   English

java.lang.NoSuchMethodError:javax.ws.rs.core.UriBuilder.resolveTemplate()使用jaxrs cxf实现

[英]java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplate() using jaxrs cxf implementation

I am creating REST client using jaxrs api with jaxrs-cfx implementation. 我正在使用jaxrs-cfx实现的jaxrs api创建REST客户端。

I am using Maven Build tool for dependency management which is like this :- 我正在使用Maven Build工具进行依赖管理,就像这样:-

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-jaxrs-client</artifactId>
  <packaging>jar</packaging>
  <name>swagger-jaxrs-client</name>
  <version>1.0.0</version>
  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!--plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jetty-version}</version>
        <configuration>
          <webApp>
            <contextPath>/</contextPath>
          </webApp>
          <webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
          <stopPort>8079</stopPort>
          <stopKey>stopit</stopKey>
          <httpConnector>
            <port></port>
            <idleTimeout>60000</idleTimeout>
          </httpConnector>
        </configuration>
        <executions>
          <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
            </goals>
            <configuration>
              <scanIntervalSeconds>0</scanIntervalSeconds>
              <daemon>true</daemon>
            </configuration>
          </execution>
          <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin-->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.9.1</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/gen/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-jaxrs</artifactId>
      <scope>compile</scope>
      <version>${swagger-core-version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback-version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>${logback-version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit-version}</version>
      <scope>test</scope>
    </dependency>
    <!-- CXF Client -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-client</artifactId>
        <version>${cxf-version}</version>
        <scope>compile</scope>
    </dependency>

     <!-- CXF server -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>${cxf-version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-service-description</artifactId>
        <version>${cxf-version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-policy</artifactId>
        <version>${cxf-version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-wsdl</artifactId>
        <version>${cxf-version}</version>
        <scope>compile</scope>
    </dependency>
  </dependencies>
  <repositories>
    <repository>
      <id>sonatype-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <swagger-core-version>1.5.9</swagger-core-version>
    <jetty-version>9.2.9.v20150224</jetty-version>
    <jersey2-version>2.22.2</jersey2-version>
    <junit-version>4.12</junit-version>
    <logback-version>1.1.7</logback-version>
    <servlet-api-version>2.5</servlet-api-version>
    <cxf-version>3.1.6</cxf-version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

and my client program is like this :- 我的客户程序是这样的:

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

import com.fasterxml.jackson.core.JsonProcessingException;

public class PsbClientJAXRS_GET {


    private final static String RESOURCE_URI = "http://localhost:2525/psb";
    public static void main(String[] args) throws JsonProcessingException {

        Client client = null;

        WebTarget webTarget = null;

        client = ClientBuilder.newClient();

        webTarget = client.target(RESOURCE_URI).path("/add-psbdata");
        webTarget = webTarget.path("/{name}").resolveTemplate("name", "Ram").path("/{id}").resolveTemplate("id", 101);

        Response response = webTarget.request().get();


        if(response.getStatus() == Status.OK.getStatusCode()){
            System.out.println("Data Passed Successfully ..... & status code is " + response.getStatus());
        }
        else{
            System.out.println("Failed to hit the server. ");
        }

    }

}

but when I am using resolveTemplate() method I am getting the error as : 但是当我使用resolveTemplate()方法时,出现以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.UriBuilder.resolveTemplate(Ljava/lang/String;Ljava/lang/Object;Z)Ljavax/ws/rs/core/UriBuilder; 线程“主”中的异常java.lang.NoSuchMethodError:javax.ws.rs.core.UriBuilder.resolveTemplate(Ljava / lang / String; Ljava / lang / Object; Z)Ljavax / ws / rs / core / UriBuilder; at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.resolveTemplate(ClientImpl.java:403) at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.resolveTemplate(ClientImpl.java:396) at com.jaxrs.test.PsbClientJAXRS_GET.main(PsbClientJAXRS_GET.java:37) 在org.apache.cxf.jaxrs.client.spec.ClientImpl $ WebTargetImpl.resolveTemplate(ClientImpl.java:403)在org.apache.cxf.jaxrs.client.spec.ClientImpl $ WebTargetImpl.resolveTemplate(ClientImpl.java:396)在com.jaxrs.test.PsbClientJAXRS_GET.main(PsbClientJAXRS_GET.java:37)

Please help me to resolve this issue. 请帮助我解决此问题。

javax.ws.rs.core.UriBuilder.resolveTemplate(String, object) is available since JAX-RS 2.0. 从JAX-RS 2.0开始javax.ws.rs.core.UriBuilder.resolveTemplate(String, object)可用。 See 看到

Some of your dependencies have included the JAX-RS 1.0 jars. 您的某些依赖项包括JAX-RS 1.0 jar。 swagger-jaxrs uses it. swagger-jaxrs使用它。 Change the artifact name to swagger-jersey2-jaxrs See documentation . 将工件名称更改为swagger-jersey2-jaxrs 请参阅文档 You may want to review the others dependencies and the code to see if this change could affect anything 您可能需要查看其他依赖项和代码,以查看此更改是否会影响任何内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll - java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util / Map - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; java.lang.NoSuchMethodError:javax.ws.rs.core.MultivaluedMap.addAll(Ljava / lang / Object; [Ljava / lang / Object;)V - java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util / Map; 将jersey ws部署到Weblogic时 - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; when deploying jersey ws to Weblogic Rest Easy Client 3.0.10 with tomcat 8 java.lang.NoSuchMethodError: javax.ws.rs.core.Response.close()V - Rest Easy Client 3.0.10 with tomcat 8 java.lang.NoSuchMethodError: javax.ws.rs.core.Response.close()V java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util / Map; 蚀工作区后出现错误 - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; error after moving eclipse workspace java.lang.NoSuchMethodError:javax.ws.rs.core.Application.getProperties()Ljava / util / Map; JIRA REST客户端 - java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; JIRA REST client 嵌套异常是 java.lang.NoSuchMethodError: javax.ws.rs.ClientErrorException.validate - nested exception is java.lang.NoSuchMethodError: javax.ws.rs.ClientErrorException.validate TomEE:javax.servlet.ServletException:java.lang.NoClassDefFoundError:无法初始化类javax.ws.rs.core.UriBuilder - TomEE: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class javax.ws.rs.core.UriBuilder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM