Dropwizard/Jersey子资源链接

Dropwizard/Jersey子资源链接,jersey,dropwizard,Jersey,Dropwizard,我正在使用Dropwizard 8.2.0构建REST服务。我有两种资源:FolderResource和FileResource: @Path("folder") public class FolderResource { @Path("{name}/file") public FileResource getFileResource() { return new FileResource(); } } public class File

我正在使用Dropwizard 8.2.0构建REST服务。我有两种资源:FolderResource和FileResource:

@Path("folder")
public class FolderResource {

   @Path("{name}/file")            
   public FileResource getFileResource() {
      return new FileResource();
   }
}

public class FileResource() {
   @GET
   @Path("{id}")
   @Produces("application/json")
   public Response getFileInfo() {
        return Response.ok().entity("{}").build();
   }
}
这里的意图是,当调用“folder/xyz/file/5”时,将调用getFileInfo()方法。 此球衣功能如下所述:

但是,当嵌入Dropwizard时,不仅不会调用getFileInfo(),而且也不会调用getFileResource()函数。 如果我将@GET annotation添加到getFileResource()方法,那么它确实会被调用,但会返回FileResource JSON表示,这当然不是目标,并且与文档中明确指出不应使用方法指示符对该方法进行注释的内容相反

我做错了什么?

@Path(“文件夹”)
@Path(“{name}/file”)
导致
文件夹{name}/file

您需要在两者之间添加斜杠,即
@Path(“/{name}/file”)
。您在
getFileInfo
上也会遇到同样的问题,因此将其重命名为
@Path(“/{id}”)