javax.ws.rs.NotFoundException:找不到完整路径的资源错误发生 [英] javax.ws.rs.NotFoundException: Could not find resource for full path Error Occures

查看:191
本文介绍了javax.ws.rs.NotFoundException:找不到完整路径的资源错误发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里几次发现了同样的问题,但是我找不到答案.

I found this same question in here few times, but I couldn't find an answer to that.

运行应用程序时,我收到以下错误消息

When I run my application, Im getting the following error

javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/RemoteQuartzScheduler/rest/TestClass/hello
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

这是项目的pom文件(我仅添加了主要部分)

Here is the pom file of the project (I only added the main parts)

<repositories>
    <repository>
        <id>JBoss repository</id>
        <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-servlet-initializer</artifactId>
        <version>3.0.9.Final</version>
    </dependency>
</dependencies>

这是我的 web.xml 文件

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">


<display-name>RemoteQuartzScheduler</display-name>

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


<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
</listener>

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>

这是我的 Test.java

@Path("/TestClass")
public class Test implements Serializable{

  private static final long serialVersionUID = -262701666015379272L;

  @GET
  @Path("/hello")
  public Response heloMessage() {

    String result = "Hello Word!!!!!!!!!";

    return Response.status(200).entity(result).build();
  }   
}

请告诉我我在哪里做错了?预先感谢

推荐答案

我没有机会测试您的版本(使用web.xml),老实说,当我使用Resteasy,所以我不会去尝试解释web.xml的错误(如果有的话).

I haven't gotten a chance to test your version (with the web.xml), and honestly I don't work much with xml when I do use Resteasy, so I won't go trying to explain what is wrong (if anything) with the web.xml.

但是当使用javax.xs.rs.core.Application子类时,我们可以定义@ApplicationPath("/path")批注.这使用/path/*的url映射为我们的JAX-RS应用程序定义了一个servlet.这是在JAX-RS规范中指定的.

But when working with an javax.xs.rs.core.Application subclass, we can define an @ApplicationPath("/path") annotation. This defines a servlet for our JAX-RS application, with the url mapping of /path/*. This is specified in the JAX-RS spec.

此处下载pdf.

You can see more here about this deployment option, as well as others, in section 2.3.2 Configuration - Servlet. This is a 1.1 spec (you are using 2.0), but the deployment options are similar. I just couldn't find an html link to the 2.0. You can download the pdf though from here.

您还可以阅读有关使用Resteasy进行部署的更多信息

You can also read more about deployments with Resteasy here in the documentation.

但是,基本上,此部署选项的作用是扫描应用程序的@Path@Provider等的批注.原因是JAX-RS将首先在覆盖的getClasses()getSingletons()中分别查找类和对象.如果然后返回空集,这将告诉JAX-RS进行扫描(按照规范).

But basically, what this deployment option does is scan for annotations of @Path, @Provider, etc for the application. The reason is that JAX-RS will first look for classes and object in overridden getClasses() and getSingletons(), respectively. If then return empty sets, this tell JAX-RS to do scanning (per the spec).

这篇关于javax.ws.rs.NotFoundException:找不到完整路径的资源错误发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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