java - 我的 REST 程序出错

标签 java tomcat glassfish

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

enter image description here 谁能告诉我这里有什么问题?

这是我的代码

@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>

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

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

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

关于java - 我的 REST 程序出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484596/

相关文章:

java - 调试tomcat应用程序时如何在windows中启动tomcat调试端口

java - 直接初始化类成员与在方法中进行初始化有什么区别?

java - Kafka 最近 X 分钟的实时平均值

java - spring-shell 和 CRaSH 有什么区别?

php - 是否可以在没有 Apache HTTP 服务器的情况下在 Apache Tomcat 6.0.32 上安装 PHP 5 和 MySQL?

java - 网 bean IDE : how to delete data source

java - 如何禁用 WebApplicationInitializer 类的 Servlet 类路径扫描,但仍显式使用我自己的实例?

Tomcat8 SSL查询

eclipse - 如何在 OS X 10.10.3 上从 Eclipse 启动 Glassfish 服务器?

java - JAX-RPC 处理程序发生异常