不知道为什么:ResourceConfig实例不包含任何根资源类 [英] No Idea why : The ResourceConfig instance does not contain any root resource classes

查看:96
本文介绍了不知道为什么:ResourceConfig实例不包含任何根资源类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是球衣和网络服务的新手,我尝试运行一个简单的RESTful Web服务。我跟着 http://www.mkyong.com/webservices / jax-rs / jersey-hello-world-example / 但我的项目不使用maven,我下载了jersey.1.17.1.jar并将其包含在我的项目路径中。

I'm new to jersey and web services and I'm try to run a simple RESTful web service. I followed http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/ but my project doesn't use maven and I download the jersey.1.17.1.jar and include it to my project path.

当我想在 http:// localhost:8080 / sycotext / rest / service / SOMETEXT 上调用服务时出现此错误:

When I want to call the service on http://localhost:8080/sycotext/rest/service/SOMETEXT I get this error :

HTTP Status 500 - Servlet.init() for servlet sycoText-servlet threw exception

这是堆栈跟踪:

javax.servlet.ServletException: Servlet.init() for servlet sycoText-servlet threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:515)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1010)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
    org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1618)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1576)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:724)

root cause

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
    com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1331)
    com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
    com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
    com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
    com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
    com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:76)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:515)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1010)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
    org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1618)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1576)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    java.lang.Thread.run(Thread.java:724)

这是我的代码:

package ir.sycotech.text.server.service;

import javax.ws.rs.*;
import javax.ws.rs.core.Response;

@Path("/service")
public class SycoTextService {
    @GET
    @Path("/{param}")
    public Response getMsg(@PathParam("param") String msg) {
        String output = "Jersey say : " + msg;
        return Response.status(200).entity(output).build();
   }

这是我的web.xml:

and here is my web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Restful Web Application</display-name>


    <servlet>
        <servlet-name>sycoText-servlet</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>ir.sycotech.text.server.service</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

</web-app>

我已经在web.xml文件中正确指定了我的包名,我不知道为什么会这样这个错误,如果有人知道是什么问题,我将非常感激

I have specified my packagename correctly in the web.xml file and I don't know why I got this error, I will be really appreciate if anyone knows what is the problem

推荐答案

错误:


com.sun.jersey.api.container.ContainerException:ResourceConfig实例不包含任何根资源类。

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

表示Jersey无法找到服务类。这可能是由 com.sun.jersey.config.property.packages 参数的错误命名包引起的,或者包名是否正确但是它不包含资源类(人们有时会忘记在课堂上添加 @Path 注释。)

means that Jersey can't find service classes. That can be caused by a wrongly named package for the com.sun.jersey.config.property.packages parameter or if the package name is correct but it does not contain resource classes (people sometimes forget to add the @Path annotation on the class).

但我找不到任何东西你的设置有误。所以这应该可行!

But I can't find anything wrong with your setup. So this should work!

检查您的应用程序是否正确部署,以及 WEB-INF / classes 文件夹实际包含您的类具有适当的文件夹路径。

Check that your application deployed correctly and that your WEB-INF/classes folder actually contains your class with the proper folder path for the package.

执行完全清理并重建然后重试。

Do a full clean and rebuild then try again.

这篇关于不知道为什么:ResourceConfig实例不包含任何根资源类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆