【问题标题】:WildFly Could not find resource for full path (no XML, using commandline deployment)WildFly 找不到完整路径的资源(没有 XML,使用命令行部署)
【发布时间】:2017-07-29 16:44:28
【问题描述】:

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

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

错误信息:

12:27:04,159 错误 [org.jboss.resteasy.resteasy_jaxrs.i18n](默认任务 1)RESTEASY002010:执行失败:javax.ws.rs.NotFoundException:RESTEASY003210:找不到完整路径的资源: 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


    【解决方案1】:

    这并不明显,但我从来没有能够在 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 之间,一切都按预期工作。

    【讨论】:

    • @Rilcon42 也检查“edit2”(虽然我猜它真的应该是它自己的答案)
    • 不能感谢你足够的人,我一直在努力反对这一点
    【解决方案2】:

    问题:

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

    REST服务有两种配置方式:

    • 注册Application类。
    • 使用@Path注解。

    你参考这个tutorial


    找不到完整路径的资源:@​​987654322@

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

    【讨论】:

    • 该教程来自 2011 年 - 您已经有一段时间无需在 web.xml 中配置任何内容了。
    • 我没有查看它的出版年份。我觉得没关系,只要两个场景的理论是一样的。
    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    相关资源
    最近更新 更多