簡體   English   中英

根資源類找到球衣休息

[英]Root resource classes found jersey rest

我正在嘗試使用jersey rest webservices創建一個簡單的webservice。 所以我創建了一個簡單的類,我稱之為main:

@Path("/main")
public class main {
@GET
@Path (value="Stringtest")
@Produces(MediaType.APPLICATION_JSON)
public String Stringtest()
{
System.out.println("************");
return ("string");
}
}

然后我更改了web.xml(我的包的名稱是“ test”)

<?xml version="1.0" encoding="ASCII"?>
<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_3_0.xsd" version="3.0">
<display-name>rest</display-name>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param> 
<param-name>com.sun.jersey.config.property.packages</param-name> 
<param-value>test</param-value> 
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

似乎在web.xml中有問題,因為我收到此錯誤

Infos: Scanning for root resource and provider classes in the packages:
test
AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Infos: Root resource classes found:
class test.main
com.sun.jersey.api.core.ScanningResourceConfig init
Infos: No provider classes found.

對這個問題有什么建議嗎? 請幫忙!

也許您的tomcat配置有問題。查看此鏈接http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

在我看來您訪問的網址錯誤

在測試課程中添加“ /”

@GET
@Path ("/Stringtest")
@Produces(MediaType.APPLICATION_JSON)
public String Stringtest()

使用此網址的訪問:( 您的上下文)/ rest / main / Stringtest

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM