路径更改后Servlet init失败了吗?

时间:2015-08-04 13:39:09

标签: java json web-services rest tomcat

我正在用java构建一个rest web服务。

这是一个方法

@Path("/json/book")
public class bookLibWS {
@GET
@Path("/test/{book}")
public Response addBook(@PathParam("book") Book aBook)  {
...}
}

我确实通过网址http://localhost:8081/BookLibWS/rest/json/book/test/test

与您联系

所有人都找到了,然后我添加了一个新方法并重命名第一个@Path的@Path

//first methode
@GET
@Path("/get/{book}")    
public Response addBook(@PathParam("book") Book aBook)  {...}

//second one
@GET
@Path("/getAllBook")
@Produces(MediaType.APPLICATION_JSON)
public List<Book> getListBook(){...}

但我知道什么时候去

http://localhost:8081/BookLibWS/rest/json/book/get/test 要么 http://localhost:8081/BookLibWS/rest/json/book/getAllBook

我收到此错误

>    Etat HTTP 500 - "Servlet.init()" pour la servlet jersey-serlvet a généré >une    exception

>type Rapport d''exception

>message "Servlet.init()" pour la servlet jersey-serlvet a généré une exception

>description Le serveur a rencontré une erreur interne qui l''a empêché de >satisfaire la requête.

exception

javax.servlet.ServletException: "Servlet.init()" pour la servlet jersey-serlvet >a généré une exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja>va:503)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2462)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2451)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:744)
cause mère

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(WebApplicati>onImpl.java:771)
    >com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplic>ati>onImpl.java:766)
    >com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer>.java:488)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.init>iate(ServletContainer.java:318)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210>)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.>java:556)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.ja>va:503)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processo>r.java:1070)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(Abstrac>tProtocol.java:611)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2>462)
    org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2451)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:>61)
    java.lang.Thread.run(Thread.java:744)
note La trace complète de la cause mère de cette erreur est disponible dans lesfichiers journaux de Apache Tomcat/7.0.56.

我认为这可能是浏览器或tomcat服务器的缓存内存造成的,所以我重启了我的服务器,清理了我的缓存,甚至重启了我的电脑&gt;&lt;

无论如何我需要帮助。

我按照本教程构建了我的WS:http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/

这是我的web.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</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>rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>


</web-app>

我正在使用apache tomcat 7.0.56

1 个答案:

答案 0 :(得分:0)

使用来自JAXB的Book注释@XmlRootElement