2013-10-16 46 views
1

我想創建一個hello例如REST服務,我遇到了以下錯誤:REST問題com.sun.jersey.api.container.ContainerException:本ResourceConfig實例不包含任何根資源類

SEVERE: Allocate exception for servlet jersey-serlvet 
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:1298) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) 
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488) 
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318) 
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609) 
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185) 
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

我查看了所有相關的帖子,也在其他博客/論壇上,但無法解決問題。

下面是我的servlet:

package com.mkyong.rest; 

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.core.Response; 

@Path("/hello") 
public class HelloWorldService { 

    @GET 
    @Path("/{param}") 
    public Response getMsg(@PathParam("param") String msg) { 

     String output = "Jersey say : " + msg; 

     return Response.status(200).entity(output).build(); 

    } 

} 

web.xml文件:

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd「> 基於REST的Web應用程序

<servlet> 
    <servlet-name>jersey-serlvet</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.mkyong.rest</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>jersey-serlvet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

和項目結構:

enter image description here

我得到的錯誤,當我嘗試訪問的網址:http://localhost:8090/RESTfulExample/rest/hello/test

我一直在努力了幾個小時來解決這個問題,但沒有任何的運氣。有沒有人在我的項目中看到錯誤?

謝謝

+0

你是如何運行它? – Welsh

+0

我使用Eclipse Indigo。 – panipsilos

+0

我有同樣的問題 –

回答

1

我有同樣的問題;在Eclipse中嘗試[Project> Clean ...]並重新啓動服務器。

1

代碼似乎很好..在eclipse中不喜歡tomcat ..將項目部署到tomcat安裝文件夾中的WEB-APPS &試試。我能夠看到這個項目的O/P .. 在解決這些問題上有興趣....

相關問題