简体   繁体   中英

Root resource classes found jersey rest

I am trying to create a simple webservice using jersey rest webservices. So I created a simple class that i called main :

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

And then I chaged web.xml ( my package's name is "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>

it seems that there is something wrong in the web.xml because i get this error

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.

Are there any suggestions to this issue? Please help!

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

Seems to me that you are accessing the wrong url

Add "/" to your test class

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

Acess with this url: (your context)/rest/main/Stringtest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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