根资源类找到了泽西休息

时间:2014-05-22 11:06:11

标签: java web-services rest jersey

我正在尝试使用jersey rest webservices创建一个简单的Web服务。所以我创建了一个名为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.

对此问题有任何建议吗?请帮忙!

2 个答案:

答案 0 :(得分:1)

也许您的tomcat配置存在问题。请检查此链接http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

答案 1 :(得分:0)

我觉得你正在访问错误的网址

将“/”添加到测试类

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

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