Using Single Jersey REST class for multiple PATH

前提是你 提交于 2019-12-11 02:22:49

问题


I have started developing REST services using JAX-RS. Using Jersey is pretty straightforward however one difference which I come across using Spring MVC and Jersey REST classes is, Spring supports having to ignore the Root Path element and have individual path mappings at Method Level. So if there is a Upload / Download Functionality, I may not want to have 2 classes one with upload and one with download which Jersey asks me to do now because there could be only 1 Root Path at class level like this:

@Path("/uploads")
public class FileDownloadController {
......
}

If I ignore the root level @Path i.e at the class level, Jersey while starting up the server doesn't recognize my class. Here is what I want to achieve:

public class FileProcessController {

   @Path("/uploads")
   public Response uploadFile(...) {
       ......
   }

   @Path("/downloads")
   public Response downloadFile(...) {
      ......
   }
}

Any clues will be appreciated.

Thanks


回答1:


Not sure if I understand the question correctly, but the following will create two endpoints in the 'Jersey root' as /uploads and /downloads. You will be able to specify other methods in the root; all of this in the same class.

@Path("/")  
public class FileProcessController {

   @Path("uploads")
   public Response uploadFile(...) {
       ...
   }

   @Path("downloads")
   public Response downloadFile(...) {
      ...
   }

}


来源:https://stackoverflow.com/questions/21980244/using-single-jersey-rest-class-for-multiple-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!