Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带jersey异常的Java rest Web服务_Java_Web Services_Rest_Jersey_Web.xml - Fatal编程技术网

带jersey异常的Java rest Web服务

带jersey异常的Java rest Web服务,java,web-services,rest,jersey,web.xml,Java,Web Services,Rest,Jersey,Web.xml,您好,我有以下java Web服务 lifevent.java: import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("LifeEventService") public class LifeEvent { // @GET here defi

您好,我有以下java Web服务

lifevent.java:

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

@Path("LifeEventService")
public class LifeEvent {

    // @GET here defines, this method will method will process HTTP GET
    // requests.
    @GET
    // @Path here defines method level path. Identifies the URI path that a
    // resource class method will serve requests for.
    @Path("/place/{numPlaces}")
    // @Produces here defines the media type(s) that the methods
    // of a resource class can produce.
    @Produces(MediaType.TEXT_XML)
    // @PathParam injects the value of URI parameter that defined in @Path
    // expression, into the method.
    public String xPlaces(@PathParam("numPlaces") int numPlaces) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        String xmlFile = "";
        xmlFile = "<Place>" + "<Location>" + "<Name>" + "Campo Grande, Lisboa"
                + "</Name>" + "<Picture>" + "<Description>"
                + "Last day of school kakakaka" + "</Description>" + "<Image>"
                + "12182621051540x13" + "</Image>" + "</Picture>" + "<People>"
                + "<Name>" + "Fábio Santos" + "</Name>" + "<Relation>"
                + "Amigo" + "</Relation>" + "</People>" + "<People>" + "<Name>"
                + "José Carilho" + "</Name>" + "<Relation>" + "Amigo"
                + "</Relation>" + "</People>" + "</Location>" + "<Place>";
        return xmlFile;
    }

    @GET
    @Path("/place/{begin}/to/{end}")
    @Produces(MediaType.TEXT_XML)
    public String getPlaceToPlace(@PathParam("begin") int begin,
            @PathParam("end") int end) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        return "";
    }

    @GET
    @Path("/people/{type}")
    @Produces(MediaType.TEXT_XML)
    public String xPeople(@PathParam("type") String type) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        return "";
    }

    @GET
    @Path("/people/{begin}/to/{end}")
    @Produces(MediaType.TEXT_XML)
    public String getPeopleToPeople(@PathParam("begin") int begin,
            @PathParam("end") int end) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        return "";
    }

    @GET
    @Path("/people/{numPeople}/important")
    @Produces(MediaType.TEXT_XML)
    public String getPeopleByImportance(@PathParam("numPeople") int numPeople) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        return "";
    }

    @GET
    @Path("/people/{numPictures}/important")
    @Produces(MediaType.TEXT_XML)
    public String getPicturesByImportance(
            @PathParam("numPictures") int numPictures) {

        // String name = i;
        // return "<User>" + "<Name>" + /*name +*/ "</Name>" + "</User>";
        return "";
    }

}
你们能帮帮我吗。我正在学习这个教程。唯一不同的是,我使用的是端口8181,这是正确的,我让它与教程一起工作,但与我的当前版本不同,我不知道为什么

编辑:


经过更多的测试,最后两种方法似乎是问题所在,我认为这是路径设置的方式。但我仍然无法找出原因。

此问题与通过param name和param value初始化Jersey包有关。你的url看起来很完美

参数值应包含有效的包名。

确保此包中存在
lifevent
类(autobiographical.aid.webservices)


这就解决了问题。

问题在于我在编辑中提到的特定web服务中的路径集


将其替换为另一个没有解决该问题的软件包。

它位于该软件包中。我不知道为什么会这样。它应该会起作用。
    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>RememberMeServer</display-name> 
    <servlet> 
    <servlet-name>Jersey REST Service</servlet-name> 
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
    <init-param> 
    <param-name>com.sun.jersey.config.property.packages</param-name> 
    <param-value>autobiographical.aid.webservices</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Jersey REST Service</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
    </servlet-mapping> 
    </web-app>
 Exception report

message Servlet.init() for servlet Jersey REST Service threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)
root cause

com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)