Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:13:25+00:00 2026-06-09T20:13:25+00:00

I am using Jersey Guice and need to configure a custom ExceptionMapper My module

  • 0

I am using Jersey Guice and need to configure a custom ExceptionMapper

My module looks like this:

public final class MyJerseyModule extends JerseyServletModule
{
   @Override
   protected void configureServlets()
   {
      ...
      filter("/*").through(GuiceContainer.class);
      ...
   }
}

And this is my ExceptionMapper:

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

public class MyExceptionMapper implements ExceptionMapper<MyException>
{
   @Override
   public Response toResponse(final MyException exception)
   {
      return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:13:26+00:00Added an answer on June 9, 2026 at 8:13 pm

    Your ExceptionMapper must be annotated with @Provider and be a Singleton.

    import com.google.inject.Singleton;
    
    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.Response.Status;
    import javax.ws.rs.ext.ExceptionMapper;
    import javax.ws.rs.ext.Provider;
    
    @Provider
    @Singleton
    public class MyExceptionMapper implements ExceptionMapper<MyException>
    {
       @Override
       public Response toResponse(final MyException exception)
       {
          return Response.status(Status.NOT_FOUND).entity(exception.getMessage()).build();
       }
    }
    

    Then just bind the ExceptionMapper in one of the Guice modules in the same Injector where your JerseyServletModule, and Jersey Guice will find it automatically.

    import com.google.inject.AbstractModule;
    
    public class MyModule extends AbstractModule
    {
       @Override
       protected void configure()
       {
          ...
          bind(MyExceptionMapper.class);
          ...
       }
    }
    

    You can also directly bind it in the JerseyServletModule if you want to:

    public final class MyJerseyModule extends JerseyServletModule
    {
       @Override
       protected void configureServlets()
       {
          ...
          filter("/*").through(GuiceContainer.class);
          bind(MyExceptionMapper.class);
          ...
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While using a Root- and SubResource in Jersey I annotated the RootResource like this
I'm using Google Guice, Guice servlet, and Jersey. I'd like to find an easy
I'm using Jersey for REST apps, i'm getting this NoClassDefException for the class AbstractRuntimeDelegate
I'm using Jersey to send HTTP POST requests like this: MultivaluedMap<String, String> form =
I'm trying to use construction injection using both Jersey-injected @Context parameters and Guice-injected parameters.
I am using Jersey v10 and have written the following code.Is this the right
I am using Jersey/Java to develop my REST services. I need to return an
I'm using Google Guice with Jersey (jax-rs). Following method throws an JAXB-Exception (JAXB can't
I'm using jersey API for some REST web services with apache Tomcat. I need
JSON is created in Java using Jersey's JAXB serializer. I need to deserialize it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.