Eric Bernier
Eric Bernier

Reputation: 489

Jersey 404 on two Resource Classes with similar @Path annotations

I have a RESTful Web service, using Drop Wizard 0.8.5 with Jersey 2.21. I have a resource class with is annotated with:

@Path("/mysite/somepath")

This class contains various methods, such as @GETs, @PUTS, etc., all working just fine.

Now, I have another resource class that is annotated with @Path("/mysite"). Within this resource class I have a need to add a few methods annotated with paths such as the following:

@Path("/somepath/dothis")
@Path("/somepath/dothat")

The resource classes all register just fine. However, when I make a call to the second class I get a 404, as it appears Jersey is looking for these methods in my first class. Is there a way to resolve this issue, other than changing my @Path annotations to avoid this naming conflict?

Upvotes: 2

Views: 1065

Answers (1)

OPK
OPK

Reputation: 4180

Jersey presumes each class has unique @Path expression associated with it. If you want to use the same @Path variable to two different resources, you either use two different path names, or you can combine the two classes into one class.

Upvotes: 5

Related Questions