WildFly 找不到完整路径的资源(无 XML,使用 CLI 部署)

问题描述 投票:0回答:2

我已经阅读有关此问题的帖子有一段时间了,但我无法弄清楚这是 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"

java xml jboss wildfly wildfly-10
2个回答
3
投票

这并不明显,但我从未能够在 JAX-RS 内容的同一路径上拥有静态内容。更改您的

JAXActivator.java
文件以具有类似
/rest
或任何您想要的路径。最终,当请求到来时,Wildfly 需要确定如何路由它。正如您现在所拥有的,您的服务从
/
开始,但静态内容也是如此。在服务和静态之间划分 URL 空间,您就不会遇到此问题。

编辑:

奇怪 - 我直接复制了你的代码并且也在 Ubuntu 下运行。我有一个全新的 Wildfly 10.1.0.Final。如果我按原样使用你的代码,我也会得到 404。但是如果我在类上添加 @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 中,效果很好。我承认我的服务上总是有额外的类级别路径来帮助确定它们的范围,但我认为这不是必需的。我还要多学习一些。

编辑2:

嗯,我学到了一些东西 - “根资源”声明(又名类级别的 @Path)是必需的。这就是为什么我的 IDE 在我没有该类时告诉我该类未使用。我一直这样做,但从来不知道这是必需的。在类级别的 @ApplicationPath 和 @Path 之间,一切都按预期工作。


0
投票

问题:

  • 看来您没有注册 REST 服务。
  • 没有在
    web.xml
    中配置servlet。

有两种方式配置REST服务:

  • 注册
    Application
    课程。
  • 使用
    @Path
    注释。

你参考这个教程


找不到完整路径的资源:http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

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

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