WildFly 找不到完整路径的资源(没有 XML,使用命令行部署)

WildFly Could not find resource for full path (no XML, using commandline deployment)

一段时间以来,我一直在阅读 SO 上关于此的线程,但我无法确定这是 WildFly 部署问题还是 RESTEASY 问题。任何帮助,将不胜感激。

当我尝试访问时:http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

错误信息:

12:27:04,159 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-1) RESTEASY002010: Failed to execute: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

JAXActivator.java

package com.sentiment360.helloworld;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

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

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>

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>Hello World WOO!</h1>
    </body>
</html>

HelloWorld.java

package com.sentiment360.helloworld;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

public class HelloWorld {
    //@Inject
    //HelloService helloService;

@GET
@Path("/json/{p}")
@Produces({ "application/json" })
public String getHelloWorldJSON(@PathParam("p") String param) {
    return "{\"result\":\"" + param + "\"}";
    //return "{\"result\":\"" + helloService.createHelloMessage(param) + "\"}";
}

@GET
@Path("/xml/{p}")
@Produces({ "application/xml" })
public String getHelloWorldXML(@PathParam("p") String param) {
    return "<xml><result>" +param+ "</result></xml>";
    //return "<xml><result>" + helloService.createHelloMessage(param) + "</result></xml>";
}
}

WildFly 服务器命令

1 号航站楼:

/etc/opt/wildfly-10.0.0.Final/bin/standalone.sh

2 号航站楼:

/etc/opt/wildfly-10.0.0.Final/bin/jboss-cli.sh --connect --command="deploy --force /home/king/NetBeansProjects/HelloWorld/target/HelloWorld-1.0-SNAPSHOT.war"

这并不明显,但我从未能够在 JAX-RS 内容的同一路径上拥有静态内容。将 JAXActivator.java 文件的路径更改为 /rest 或任何您喜欢的路径。最终,当请求传入时,Wildfly 需要确定如何路由它。正如您现在拥有的那样,您的服务从 / 开始,但静态内容也是如此。将您的 URL space 划分为服务和静态,这样您就不会 运行 陷入这个问题。

编辑:

很奇怪 - 我直接复制了你的代码并且也在 运行ning 下 Ubuntu。我有一个全新的 Wildfly 10.1.0.Final。如果我按原样使用您的代码,我也会得到 404。但是如果我在 class:

上添加 @Path 注释
package com.sentiment360.helloworld;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

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

    @GET
    @Path("/json/{p}")
    @Produces({"application/json"})
    public String getHelloWorldJSON(@PathParam("p") String param) {
        return "{\"result\":\"" + param + "\"}";
    }

    @GET
    @Path("/xml/{p}")
    @Produces({"application/xml"})
    public String getHelloWorldXML(@PathParam("p") String param) {
        return "<xml><result>" + param + "</result></xml>";
    }
}

并将该路径包含在 URL 中它工作正常。我承认我的服务上总是有额外的 class 级别路径来帮助确定它们的范围,但我认为这不是必需的。我还要学习更多。

编辑 2:

嗯,我学到了一些东西 - "root resource" 声明(a.k.a。class 级别的 @Path)是必需的。这就是为什么我的 IDE 告诉我 class 在我没有时未使用的原因。我一直都是这样做的,但从来不知道这是必需的。在 class 级别的 @ApplicationPath 和 @Path 之间,一切都按预期工作。

问题:

  • 您似乎没有注册 REST 服务。
  • 未在 web.xml 中配置 servlet。

配置REST服务有两种方式:

  • Application class.
  • 中注册
  • 使用 @Path 注释。

你参考这个tutorial


Could not find resource for full path: http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

我认为 Web 容器将此 URL 视为静态页面而不是 servlet。所以你对应的REST路径(/json/hi)不会得到request.