java - 在 CXF GET、PUT 和 DELETE 资源上获取 404,而 POST 工作正常

标签 java rest cxf jax-rs

我有以下服务..

@Path("/persistence")
public interface Persistence {

  @GET
  @Produces("application/json")
  @Path("/projects/{pid}/items")
  public Response getItems(@PathParam("pid") String projectId);

  @POST
  @Produces("application/json")
  @Consumes("application/json")
  @Path("/items")
  public Response addItems(String payload);

  @GET
  @Produces("application/json")
  @Path("/items/{itemId}")
  public Response getItem(@PathParam("itemId") String itemId);

  @PUT
  @Consumes("application/json")
  @Path("/items/{itemId}")
  public Response updateItem(@PathParam("itemId") String itemId,String payload);

  @DELETE
  @Consumes("application/json")
  @Path("/items/{itemId}")
  public Response deleteItem(@PathParam("itemId") String itemId);

}

我在tomcat上部署了这个服务,一切都很好。服务已部署,没有任何错误。之后,当我尝试测试它时,只有 POST 有效,而所有其他资源都会导致 404 未找到错误。我正在使用 REST 控制台来测试该服务。当我这样做时也是如此

http://localhost:8081/serv?_wadl

我只看到列出的 POST 端点,列表中没有显示任何 GET、PUT 或 DELETE 资源。我缺少什么?

最佳答案

此服务被声明为接口(interface)

实现这个接口(interface)的类在哪里?

使用 JAX-RS 时有一些关于“注释继承”的规则。

JAX-RS 1.1 - 3.6 注解继承:

JAX-RS annotations MAY be used on the methods and method parameters of a super-class or an implemented interface. Such annotations are inherited by a corresponding sub-class or implementation class method provided that method and its parameters do not have any JAX-RS annotations of its own. Annotations on a super-class take precedence over those on an implemented interface. If a subclass or implementation method has any JAX-RS annotations then all of the annotations on the super class or interface method are ignored.

关于java - 在 CXF GET、PUT 和 DELETE 资源上获取 404,而 POST 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17666973/

相关文章:

部署小程序时,Glassfish 中出现 java.lang.reflect.InitationTargetException

java - 如何从 Mongo Document 转换为 java Set<String>?

java - 为什么我的代码修改了错误的数组?

java - 如何获取 3G 网络的小区 ID?

javascript - 要求服务器删除记录

javascript - 轻松模拟 Restful 服务的工具

java - 解析对java对象的soap xml响应

node.js - 使用 'ionic run android'从android发送post请求到nodejs本地主机服务器

rest - 无法为 Apache CXF 和 JAX-RS 配置 SSL

jax-rs - 如何将 CXF ResourceComparator 与 Openliberty 结合使用