首页 文章

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

提问于
浏览
0

我一直在阅读有关此问题的线程,但我无法弄清楚这是WildFly部署问题还是RESTEASY问题 . 任何帮助,将不胜感激 .

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

错误消息:

12:27:04,159 ERROR [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>";
}
}

pic to show my directory directory structure

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"

2 回答

  • 2

    它在JAX-RS内容的相同路径上从未能够拥有静态内容 . 将 JAXActivator.java 文件更改为具有类似 /rest 的路径或任何您想要的路径 . 最终,当Wildfly中的请求需要确定如何路由它时 . 正如您现在所拥有的,您的服务始于 / ,但静态内容也是如此 . 在服务和静态之间对URL空间进行分区,您将不会遇到此问题 .

    EDIT:

    很奇怪 - 我直接复制了你的代码,也在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中包含该路径它工作正常 . 我承认我总是在我的服务上有额外的类级别路径来帮助确定范围,但我认为这不是必需的 . 我还需要学习更多 .

    EDIT 2:

    好吧,我学到了一些东西 - “根资源”声明(a.k.a.在类级别的@Path)是必需的 . 这就是为什么我的IDE告诉我,当我没有它时,该类未被使用 . 我总是这样做,但从来不知道它是必需的 . 在类级别的@ApplicationPath和@Path之间,它们都按预期工作 .

  • 0

    问题:

    • 看来你没注册REST服务 .

    • 未在 web.xml 中配置servlet .

    有两种配置REST服务的方法:

    • Application 课程中注册 .

    • 使用 @Path 注释 .

    你指的是tutorial


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

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

相关问题