如何发布“Hello world”Rest Web服务?

时间:2014-01-14 07:31:11

标签: java web-services java-ee connectexception

package my.first.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("hello")
public class Hello {

  // This method is called if TEXT_PLAIN is requested
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayHelloInPlainText() {       
    return "Hello world!";
  }
 http://stackoverflow.com/questions/2893796/create-hello-world-with-restful-web-service-and-jersey
  // This method is called if HTML is requested
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHelloInHtml() {
    return "<html> " + "<title>" + "Hello world!" + "</title>"
        + "<body><h1>" + "Hello world!" + "</body></h1>" + "</html> ";
  }
}

这是我编写的Web服务Restful的代码。当我使用Test Client发布时,此错误即将发生:

IWAB0489E Error when deploying Web service to Axis runtime
  axis-admin failed with  {http://schemas.xmlsoap.org/soap/envelope/}
  Server.userException java.net.ConnectException: Connection refused: connect

我该如何解决?这只是Rest,而不是SOAP。

1 个答案:

答案 0 :(得分:0)

你必须下载泽西[sunmicrosystem的REST实现]并在你的应用程序中包含这些jar,除此之外你必须相应地修改你的web.xml。
网上有多个初学者教程 - click here