javax.ws.rs.NotFoundException:找不到完整路径资源

问题描述 投票:8回答:3

环境

Windows 7(64)
jdk1.7.0_51(64)
RESTEasy3.0.7
apache-tomcat-7.0.50
Project Name: hello

rest easy HelloWorld service.Java:

package com.javacodegeeks.enterprise.rest.resteasy;

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.MediaType;

@Path("/RESTEasyHelloWorld")
public class RESTEasyHelloWorldService {

    @GET
    @Path("/{param}")
    @Produces(MediaType.TEXT_PLAIN)
    public String getMsg(@PathParam("param") String name) {
        String msg = "Rest say: good " + name;
        return msg;
    }
}

veb.hml:

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

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

    <!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- 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>

</web-app>

为什么我得到的异常时,我称之为http://localhost:8080/hello/rest/RESTEasyHelloWorld/a回报:

javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/hello/rest/RESTEasyHelloWorld/a
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
...
java resteasy
3个回答
6
投票

你可以尝试使用http://localhost:8080/hello/RESTEasyHelloWorld/a。 (如果没有/rest)。

如果你想使用/rest,你可以修改你RESTEasyHelloWorldService @Path到/rest/RESTEasyHelloWorld


但根据您所使用的API的版本,你可以做一个简单得多的工作,让你的RESTful服务工作。

我假设你有你的类路径RestEasy的-JAXRS库。

既然你没有使用JBoss EAP或者,你也需要得到RestEasy的-servlet的初始化。文档使用的Servlet 3.0容器,如TOMCAT here

您将需要扩展应用程序,创建例如RESTEasyService:

@ApplicationPath("/rest")
public class RESTEasyService extends Application {
}

你并不需要提供该类任何实现,因为的RESTEasy会扫描所有的供应商和资源。文档使用Application类here

留下你RESTEasyHelloWorldService就像你在你的问题说:

@Path("/RESTEasyHelloWorld")
public class RESTEasyHelloWorldService {

    @GET
    @Path("/{param}")
    @Produces(MediaType.TEXT_PLAIN)
    public String getMsg(@PathParam("param") String name) {
        String msg = "Rest say: good " + name;
        return msg;
    }
}

现在,你的web.xml不需要任何东西。 Java的WS-RS和的RESTEasy已经在做的一切。

你的web.xml可以是这样的:

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

    <display-name>hello</display-name>

</web-app>

的RESTEasy官方文档是在开始有点混乱,但一旦你理解了实现是JBOSS和非JBoss应用程序(只需使用该改变林达)一样,你得到的东西去容易。


4
投票

我得到了同样的问题,当我试图3.0.11.Final

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.11.Final</version>
</dependency>

但是当我与另一个版本尝试它的工作。

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.4.Final</version>
</dependency>

而且因为你已经在web.xml中。希望这有助于提到/休息你试图打开的网址(http://localhost:8080/hello/rest/RESTEasyHelloWorld/a)是正确的。


2
投票

我有同样的问题,当我迁移我的应用程序从RestEasy的版本3.0.4到3.0.12

Web服务是工作的罚款类似于一个user3926093上面粘贴的web.xml。我发布的是版本3.0.7正在改变点。该版本之前,你甚至不需要RestEasy的-servlet的初始化为fasfsfgs如上所述。但随着3.0.7及以后的版本我开始“的完整路径找不到资源:”异常。

我为了让它工作所做的是改变的web.xml看起来与上面相同fasfsfgs规定(基本上我删除了其中的所有配置)和我创建javax.ws.rs.core.Application类的子类,也可以作为fasfsfgs上述但我不同意,“你不需要提供该类任何实现”。你如何能实现这个类的方法可以在这里找到:https://goo.gl/9TJ3Y2。请注意,如果您希望每个请求的模型比这个实现是对你不好。而最后不要忘记添加RestEasy的-servlet的初始化依赖。

© www.soinside.com 2019 - 2024. All rights reserved.