简体   繁体   English

Tomcat在页面加载时出现500错误

[英]Tomcat giving 500 error on page load

I'm new to tomcat and jersey so hopefully this isn't a stupid mistake. 我是tomcat和jersey的新手,所以希望这不是一个愚蠢的错误。 Whenever I try and access my project located at http://127.0.0.1:8080/first/rest/hello I get the following error... 每当我尝试访问位于http://127.0.0.1:8080/first/rest/hello项目时,我都会收到以下错误...

javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:679)

root cause

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not     contain any root resource classes.
com.sun.jersey.server.impl.application.RootResourceUriRules.<init>   (RootResourceUriRules.java:99)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationIm  pl.java:1298)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(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:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:679)

I've got a Java class and a web.xml file for this project. 我有一个Java类和这个项目的web.xml文件。 They are the following... 他们是以下......

Hello.java Hello.java

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 request
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
    return "Hello Jersey";
}

// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}

// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
    return "<html> " + "<title>" + "Hello Jersey" + "</title>"
            + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}

}

web.xml web.xml中

<?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>first</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>first</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>

What am I missing? 我错过了什么?

EDIT: It's probably relevant that I've been using the following tutorial to get started. 编辑:我可能已经开始使用以下教程了。 http://www.vogella.de/articles/REST/article.html#first http://www.vogella.de/articles/REST/article.html#first

Best way how to start is look at tested working samples. 如何开始的最佳方式是查看经过测试的工作样本。 So.. please see following: 所以......请看以下内容:

Helloworld-webapp: https://maven.java.net/content/repositories/releases/com/sun/jersey/samples/helloworld-webapp/1.9.1/helloworld-webapp-1.9.1-gf-project.zip Helloworld-webapp: https//maven.java.net/content/repositories/releases/com/sun/jersey/samples/helloworld-webapp/1.9.1/helloworld-webapp-1.9.1-gf-project.zip

And by the way, that error message means "Jersey is not able to find ANY @Path annotated class". 顺便说一下,该错误消息意味着“Jersey无法找到任何@Path注释类”。 My bet would be on this: 我的赌注是这样的:

<init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>first</param-value>
</init-param>

Is "first" really name of the package where "Hello" class resides? “第一个”真的是“Hello”类所在的包的名称吗?

In jersey 2.x docs use 在球衣2.x docs使用

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>com.rest.portal</param-value>
</init-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM