Jersey-ResourceConfig实例不包含任何根资源类

时间:2016-04-04 05:38:56

标签: java jersey restful-architecture

我正在学习使用运动衫的休息服务。但是在tomcat Apache-tomcat-7.0.68中部署Hello World示例时会出现以下错误。

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1331)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)

请帮助某人解决此问题。

Java Class

package com.tutorialacademy.rest; 
import java.util.Date; 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response; 

@Path("/")
public class RESTfulHelloWorld {

@GET
@Produces("text/html")
public Response getStartingPage()
{
    String output = "<h1>Hello World!<h1>" +
            "<p>RESTful Service is running ... <br>Ping @ " + new Date().toString() + "</p<br>";
    return Response.status(200).entity(output).build();
}

}

的web.xml

<servlet>
    <servlet-name>helloworld</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>com.tutorialacademy.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>helloworld</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

0 个答案:

没有答案