我的 REST 程序出错

Error in my REST Program

当我在 tomcat 服务器上 运行 我的 Web 应用程序时出现此错误。

谁能告诉我这是怎么回事?

这是我的代码

@Path("/robot")
public class Robot {
@POST
//@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
//@Produces(MediaType.APPLICATION_JSON)
public Response displayTemperature(ProcessModel tempData){
    System.out.println(" \n\n ");

    System.out.println( "|The temp is : "+ tempData.getTemperature() +"     "+ " Robot deployment time is " + "  "+tempData.getTime() +"  |");

    Client client = Client.create();
    WebResource webResource2 = client.resource("http://localhost:8080/RESTServer/rest/hello/run");
    ClientResponse response2 = webResource2.get(ClientResponse.class);
    if (response2.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
    }

    String output2 = response2.getEntity(String.class);
    System.out.println("\n<<<============  POSTING command to Robot Info Model  ============>>>");
    System.out.println(output2);
    return Response.ok(200).header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS").entity("POSTED").build();
} 
}

使用 maven 并在所需的依赖项中构建项目。

如前所述,根据使用的版本添加 jersey 客户端依赖:

http://mvnrepository.com/artifact/com.sun.jersey/jersey-client

1.19 版本示例:

<dependency>
     <groupId>com.sun.jersey</groupId>
     <artifactId>jersey-client</artifactId>
     <version>1.19</version>
</dependency>

在您的 pom.xml 文件中添加之前的 XML 代码

对于类路径解析,并且仅当您使用 Maven 时,请查看此 link: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

提示:当您不知道什么类路径 scope 与 maven 一起使用时,请使用编译路径。但我建议你理解这个基本概念