我有以下服务..
@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/