我有一个类作为子资源,当运行时,除了eclipse显示红色下划线之外,所有的工作都没有错误,我如何让eclipse“知道”父@Path是它的一部分。
例如。
在MessageResouce中
@Path("/{messageId}/comments")
public CommentResource getCommentResource() {
return new CommentResource();
}
在CommentResource中
@Path("/") // optional for subresources
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
public class CommentResource {
private CommentService commentService = new CommentService();
@GET
public List<Comment> getAllComments(@PathParam("messageId") long messageId) {
return commentService.getAllComments(messageId);
}
@POST
public Comment addMessage(@PathParam("messageId") long messageId,
Comment comment) {
return commentService.addComment(messageId, comment);
}
@PUT
@Path("/{commentId}")
public Comment updateMessage(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId, Comment comment) {
comment.setId(commentId);
return commentService.updateComment(messageId, comment);
}
@GET
@Path("/{commentId}")
public String test2(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId) { // messageId still gets
// passed from parent
// resource
return "Method return commment id: " + commentId + " and messageId: "
+ messageId;
}
@DELETE
@Path("/{commentId}")
public void deleteComment(@PathParam("messageId") long messageId,
@PathParam("commentId") long commentId) {
commentService.removeComment(messageId, commentId);
}
}
所有的messageId路径参数都带有错误的红色下划线,但一切都运行得很好,看到这一点很烦人,我不想让任何人看到我的代码时抓狂。
谢谢
发布于 2015-10-28 09:42:28
我也有同样的问题,但我通过转到Preferences -> JAX-RS -> JAX-RS Validator -> JAX-RS资源方法并选中Unbound @PathParam注释值作为警告或忽略(默认是错误)来解决它。在忽略情况下,您将不再看到该消息。根据我所读到的内容,可能与JAX-RS验证有关。我使用的是JAX-RS1.1和Jersey 1.19 (不确定在JAX-RS2.0中是否会有相同的行为)。
发布于 2015-11-04 13:30:56
根据我的经验,当多个带注释的HTTP方法函数包含在同一个注入类中时,Eclipse/JBoss Developer Studio中的JAX-RS验证会出错。例如,单个@GET方法不会触发任何警报,但添加@POST方法会使验证器无法准确检测各种@PathParam和@Path语句之间的绑定。
这很烦人,但不会对代码编译或执行产生负面影响。
正如Corina解释的那样,唯一实际的选择是编辑IDE首选项以降低异常的严重程度。我选择“警告”而不是“忽略”,这样就不会完全禁止任何合法的错误。
发布于 2022-01-06 00:57:04
我遇到了这种问题,因为我为我的@PathParam
使用了错误的导入javax.websocket.server.PathParam;
。我的API测试起作用了,但JAXRS对此并不满意。使用javax.ws.rs.PathParam;
可以解决您的问题。
https://stackoverflow.com/questions/31127360
复制相似问题