RestEasy路径求解
我得到这样的东西
import javax.ws.rs.GET;
import javax.ws.rs.Path;
public class xxx
{
@GET
@Path(value = "path1")
public Response m1(@QueryParam(value = "a") String a)
{
...
}
@GET
@Path(value = "path2")
public Response m2(@QueryParam(value = "b") String b)
{
...
}
}
使用restEasy我得到HTTP状态404 - 每次当我尝试获取path1或path2时无法找到相对的资源 例如 http://someip:8080/myserv/services/path1?a=asd
这里 http://docs.jboss.org/resteasy /docs/1.2.GA/userguide/html_single/#Using_Path 我读过
@javax.ws.rs.Path 注释必须存在于类和/或资源方法上。如果它同时存在于类和方法中,则资源方法的相对路径是类和方法的串联。
I get something like this
import javax.ws.rs.GET;
import javax.ws.rs.Path;
public class xxx
{
@GET
@Path(value = "path1")
public Response m1(@QueryParam(value = "a") String a)
{
...
}
@GET
@Path(value = "path2")
public Response m2(@QueryParam(value = "b") String b)
{
...
}
}
With restEasy I get HTTP Status 404 - Could not find resource for relative every time when i try to get path1 or path2
For ex http://someip:8080/myserv/services/path1?a=asd
Here http://docs.jboss.org/resteasy/docs/1.2.GA/userguide/html_single/#Using_Path I read
The @javax.ws.rs.Path annotation must exist on either the class and/or a resource method. If it exists on both the class and method, the relative path to the resource method is a concatenation of the class and method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
services
不是 servlet 映射或路径的一部分,请将其删除。(此外,有关您的路径/servlet 映射的更多信息将使我们更好地理解)
编辑:
因此您的项目是使用 myapp 上下文名称部署的 + 您有服务前缀 + 在资源类中定义的路径。+ servlet 映射是 /* 所以 /myapp/services /路径应该可以工作。
您可以提高 Resteasy 类的日志记录级别以查看问题所在。 中看到请求的路径
或者在调试模式下,您可以在 PathHelper.replaceEnclosureCurlyBraces EDIT2
注释类
:如果您是自动扫描,则需要使用 @Provider Resteasy v1.2.1
Remove
services
if it is not a part of your servlet mapping or path.(Also more info about your path/servlet mapping will make us understand better)
EDIT:
So your project is deployed with myapp context name + you have services prefix + path defined in resource class.+ servlet mapping is /* so /myapp/services/path should work.
You can increase the logging level for resteasy classes to see what is wrong. or in debug mode you can see what path is requested in PathHelper.replaceEnclosedCurlyBraces
EDIT2:
If you are auto scanning, classes needs to be annotated with @Provider
Resteasy v1.2.1
您是否尝试删除路径符号中的 value= ?我不是 100% 知道 value= 的用途,因为我对 JAX-RS 很陌生,但也许尝试这样做:
Did you try removing the value= in your path notation? I'm not 100% on what the value= is used for since I'm quite new to JAX-RS but maybe try out just doing: