Java WildFly找不到完整路径的资源(没有XML,使用命令行部署)
我已经阅读了一段时间关于这方面的文章,但我不知道这是一个WildFly部署问题还是一个RESTEASY问题。任何帮助都将不胜感激 当我尝试访问时:Java WildFly找不到完整路径的资源(没有XML,使用命令行部署),java,xml,jboss,wildfly,wildfly-10,Java,Xml,Jboss,Wildfly,Wildfly 10,我已经阅读了一段时间关于这方面的文章,但我不知道这是一个WildFly部署问题还是一个RESTEASY问题。任何帮助都将不胜感激 当我尝试访问时:http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi 错误消息: 12:27:04159错误[org.jboss.resteasy.resteasy_jaxrs.i18n](默认任务-1)RESTEASY002010:无法执行:javax.ws.rs.NotFoundException:RESTEA
http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi
错误消息:
12:27:04159错误[org.jboss.resteasy.resteasy_jaxrs.i18n](默认任务-1)RESTEASY002010:无法执行:javax.ws.rs.NotFoundException:RESTEASY003210:无法找到完整路径的资源:
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>
起始页
你好,World-WOO!
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>";
}
}
package com.com.360.helloworld;
导入javax.inject.inject;
导入javax.ws.rs.GET;
导入javax.ws.rs.Path;
导入javax.ws.rs.PathParam;
导入javax.ws.rs.products;
公共类HelloWorld{
//@注入
//HelloService HelloService;
@得到
@路径(“/json/{p}”)
@产生({“应用程序/json”})
公共字符串getHelloWorldJSON(@PathParam(“p”)字符串参数){
返回“{\”结果\”:\“+param+”\“}”;
//返回“{\“result\”:\”+helloService.createHelloMessage(param)+“\”}”;
}
@得到
@路径(“/xml/{p}”)
@产生({“应用程序/xml”})
公共字符串getHelloWorldXML(@PathParam(“p”)字符串参数){
返回“+param+”;
//返回“+helloService.createHelloMessage(param)+”;
}
}
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空间,您将不会遇到此问题
编辑:
奇怪-我直接复制了你的代码,并且在Ubuntu下运行。我有一个全新的Wildfly 10.1.0决赛。如果我按原样使用你的代码,我也会得到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>";
}
}
package com.com.360.helloworld;
导入javax.ws.rs.GET;
导入javax.ws.rs.Path;
导入javax.ws.rs.PathParam;
导入javax.ws.rs.products;
@路径(“/hello”)
公共类HelloWorld{
@得到
@路径(“/json/{p}”)
@产生({“应用程序/json”})
公共字符串getHelloWorldJSON(@PathParam(“p”)字符串参数){
返回“{\”结果\”:\“+param+”\“}”;
}
@得到
@路径(“/xml/{p}”)
@产生({“应用程序/xml”})
公共字符串getHelloWorldXML(@PathParam(“p”)字符串参数){
返回“+param+”;
}
}
并将该路径包含在URL中,这样就可以正常工作。我承认,我的服务中总是有额外的类级别路径来帮助确定它们的范围,但我认为这不是必需的。我还得学点东西
编辑2:
嗯,我学到了一些东西——“根资源”声明(即类级别的@Path)是必需的。这就是为什么我的IDE告诉我这个类没有使用,而我没有它。我总是这样做,但从不知道这是必要的。在类级别的@ApplicationPath和@Path之间,它们都按照预期工作。这并不明显,但我从未能够在JAX-RS内容的同一路径上拥有静态内容。将
JAXActivator.java
文件更改为具有类似/rest
的路径或任何您想要的路径。最终,当请求传入时,Wildfly需要确定如何路由它。现在,您的服务从/
开始,但静态内容也是如此。在服务和静态之间划分URL空间,您将不会遇到此问题
编辑:
奇怪-我直接复制了你的代码,并且在Ubuntu下运行。我有一个全新的Wildfly 10.1.0决赛。如果我按原样使用你的代码,我也会得到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>";
}
}
package com.com.360.helloworld;
导入javax.ws.rs.GET;
导入javax.ws.rs.Path;
导入javax.ws.rs.PathParam;
导入javax.ws.rs.products;
@路径(“/hello”)
公共类HelloWorld{
@得到
@路径(“/json/{p}”)
@产生({“应用程序/json”})
公共字符串getHelloWorldJSON(@PathParam(“p”)字符串参数){
返回“{\”结果\”:\“+param+”\“}”;
}
@得到
@路径(“/xml/{p}”)
@产生({“应用程序/xml”})
公共字符串getHelloWorldXML(@PathParam(“p”)字符串参数){
返回“+param+”;
}
}
并将该路径包含在URL中,这样就可以正常工作。我承认,我的服务中总是有额外的类级别路径来帮助确定它们的范围,但我认为这不是必需的。我还得学点东西
编辑2:
嗯,我学到了一些东西——“根资源”声明(即类级别的@Path)是必需的。这就是为什么我的IDE告诉我这个类没有使用,而我没有它。我总是这样做,但从不知道这是必要的。在类级别的@ApplicationPath和@Path之间,一切都按预期工作。问题:
- 您似乎没有注册您的REST服务
- 未在
中配置servletweb.xml
- 在
类中注册应用程序
- 使用
注释@Path
找不到完整路径的资源: 我认为web容器将此URL视为静态页面