gpt4 book ai didi

web-services - 如何运行 Rest WS?

转载 作者:行者123 更新时间:2023-12-04 06:20:44 28 4
gpt4 key购买 nike

当我尝试在浏览器上运行 Java REST WS 时出现以下错误:

HTTP 状态 500 -

输入异常报告

信息

说明 服务器遇到内部错误 (),阻止它完成此请求。

异常(exception)

javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception  
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Unknown Source)

根本原因
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(WebApplicationImpl.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:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Unknown Source)

注意 Apache Tomcat/6.0.20 日志中提供了根本原因的完整堆栈跟踪。

Apache Tomcat/6.0.20

请让我知道是什么问题?

我是否必须为此创建任何 servlet?

我的java类如下:
import javax.ws.rs.GET;  
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


//POJO, no interface no extends

//The class registers its methods for the HTTP GET request using the @GET annotation.
//Using the @Produces annotation, it defines that it can deliver several MIME types,
//text, XML and HTML.

//The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/hello")

public class Welcome {
// 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 :

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID"version="2.5">
你好

索引.html


Jersey REST 服务
com.sun.jersey.spi.container.servlet.ServletContainer
<init-param>  
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>Hello</param-value>
</init-param>

<load-on-startup>1</load-on-startup>



Jersey REST 服务
/休息/*

最佳答案

我在 web.xml 中进行了以下更改,问题得到解决:

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

问候,
斯内哈

关于web-services - 如何运行 Rest WS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6605789/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com