泽西岛REST ResourceConfig实例不包含任何根资源类 [英] Jersey REST The ResourceConfig instance does not contain any root resource classes

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

问题描述

尽管这是一个古老的问题,但我仍然找不到使这项工作成功的答案. 如果您发现我的任何说法不正确,请更正.

Although this is one ancient question, I still can not find the answer to make this work. Please correct if you find any of my statement is not correct.

我有一个Java Face应用程序,并将REST用于Web服务.我认为Face与我的问题完全无关. web.xml是:

I have a Java Face app and use REST for the Web Services. I don't think Face has anything to do with my problem at all. The web.xml is:

<servlet>
    <servlet-name>NDREST</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.bi.nd.webservice</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>NDREST</servlet-name>
    <url-pattern>/nd/*</url-pattern>
</servlet-mapping>

由于它是具有Trinidad等的Face应用程序,因此web.xml中还有很多servlet.

I have quite a few more servlets in the web.xml since is is a Face app with Trinidad, etc.

在com.bi.nd.webservice包中,我的资源类是:

In the package com.bi.nd.webservice, my resource class is:

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Produces(MediaType.APPLICATION_XML)
@Path("/hello")
public class TransactionResource 
{
public TransactionResource() 
{
}

@GET
@Produces(MediaType.TEXT_PLAIN)
public String itWorks()
{
    return "Get is OK";
}
}

我的类具有@GET的事实足以将其自身标识为资源类.
更不用说其他复杂性了,我在Eclipse中用Ant编译了我的源代码,并且在catalina.out文件中得到了这个错误:

The fact that my class has a @GET is enough to identify itself a resource class.
Let alone all other complexities, I compiled my source code with Ant in Eclipse and I got this error in the catalina.out file:

May 24, 2011 8:48:46 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
     com.bi.nd.webservice
May 24, 2011 8:48:46 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.7 05/20/2011 11:04 AM'
May 24, 2011 8:48:46 AM com.sun.jersey.server.impl.application.RootResourceUriRules <init>
SEVERE: The ResourceConfig instance does not contain any root resource classes.

有人建议将asm.jar,jsr-api.jar,jersey-server.jar和jersey-core.jar复制到应用程序WEB-INF/lib中.我做到了,但仍然没有奏效. 我发现这个建议有点奇怪,因为WEB-INF/lib是Eclipse从构建路径安装所有依赖库的地方.这里不是我们手动放置库的地方.

Some suggested that copy the asm.jar, jsr-api.jar, jersey-server.jar and jersey-core.jar into the app WEB-INF/lib. I did that and it still did not work. I found the suggestion was a bit odd since WEB-INF/lib is a place where Eclipse will install all dependency libraries from the build path. It is not a place where we manually put libraries.

有人解释说此错误与Java插件以及Jersey的编写方式有关.但这是几年前的事情.

Some explained that this error had something to do with Java plug-in and the way Jersey was written. But that was years ago.

有人可以向我解释为什么我一直遇到这个问题吗?

Can some one explains to me why I keep having this problem?

后续行动: 尽管来自REST网站,但是定义为Root资源类的资源类是POJO(普通的Java对象),它们要么用@Path注释,要么至少有一个用@Path注释的方法或诸如@ GET,@ PUT之类的请求方法指示符,@ POST或@DELETE.资源方法是带有请求方法指示符的资源类方法.本节介绍如何使用Jersey来注释Java对象以创建RESTful Web服务.

Followup: Although from REST web site, resource class defined as Root resource classes are POJOs (Plain Old Java Objects) that are either annotated with@Path or have at least one method annotated with @Path or a request method designator such as @GET, @PUT, @POST, or @DELETE. Resource methods are methods of a resource class annotated with a request method designator. This section describes how to use Jersey to annotate Java objects to create RESTful web services.

我必须在类中添加@Path("/hello"),突然Jersey可以找到我的资源类

I have to add @Path("/hello") to my class, and suddenly Jersey can find my resource class

现在catalina.out文件如下:

Now the catalina.out file looks like:

May 24, 2011 3:13:02 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
com.bi.nd.webservice
May 24, 2011 3:13:02 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class com.bi.nd.webservice.TransactionResource
May 24, 2011 3:13:02 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 24, 2011 3:13:02 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.7 05/20/2011 11:04 AM'

但是问题还远没有结束.我尝试访问URL http://localhost:8080/nd/hello,但仍然得到404 NOT FOUND. Provider类不是重要消息吗?

But the problem is far from over. I try to access the URL http://localhost:8080/nd/hello and I still get the 404 NOT FOUND. Is the Provider class NOT FOUND an important message?

推荐答案

我遇到了相同的错误消息,并通过修改web.xml文件解决了该错误消息.确保其中包含以下内容:

I had the same error message and solved it by modifying my web.xml file. Make sure it has this in it:

<init-param>
   <param-name>com.sun.jersey.config.property.packages</param-name>
   <param-value>your.package.name.here</param-value>
</init-param>

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

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