title: Global Exception Handling in Jersey & Spring?
body: <p>I am developing the RESTful webservices using Jersey &amp; Spring 3.2 along with Open CMIS.</p>
  
  <p>I am not using MVC pattern of Spring and it's just Spring IOC &amp; Jersey SpringServlet, the controller class is something like below code </p>
  
  <pre><code>@GET
  @Path("/{objId:.+}")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  
  public statusMsg addObject(@PathParam("objId") String objId{
  
      return repoService.addObject(objId);
  }
  </code></pre>
  
  <p>In the repoService I am performing the business logic to add the object using CMIS, my question is that I am catching around 5 exceptions related to CMIS then the base exception i.e Exception but for every service method I have to repeat it which I don't want to do.</p>
  
  <p>I was searching on Google and found that @ControllerAdvice is the best solution for such problem wheer you can define all the checked &amp; unchecked exceptions and wherever remove all the try catch blocks from the application. But it only work with MVC pattern.</p>
  
  <p>Question 1: Is there a way I can use this in above Jersey-Spring framework?</p>
  
  <p>After more reserach I found that Jersey provides ExceptionMapper to handle customized exception but I want to catch more CMIS exception or default Exception or IO Exception etc.</p>
  
  <p>Question 2: How can I do it with ExceptionMapper?</p>
  
  <p>Question 3: Am I on the correct approach or do you suggest any better approach to handle such issues.</p>
  
  <p>Thanks in advance.</p>