Is there a difference between @Path having value starting with "/" and without it
I have tested both usage, all work properly.
@Path("message")
public class MessageServices {
@PUT
@Path("sendsms")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON})
public Response sendSms() {
//....
}
}
@Path("/message")
public class MessageServices {
@PUT
@Path("/sendsms")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.APPLICATION_JSON})
public Response sendSms() {
//....
}
}
I've never seen any difference. And the documentation for @Path
(http://docs.oracle.com/javaee/7/api/javax/ws/rs/Path.html) says:
Paths are relative. For an annotated class the base URI is the application path, see ApplicationPath. For an annotated method the base URI is the effective URI of the containing class. For the purposes of absolutizing a path against the base URI , a leading '/' in a path is ignored and base URIs are treated as if they ended in '/'.
So there should not be any difference.
According to this tutorial:
A @Path value isn’t required to have leading or trailing slashes (/). The JAX-RS runtime parses URI path templates the same whether or not they have leading or trailing spaces.
So it seems like there is no difference.
P.S. I've seen a minor difference once upon a time that was not directly related to JAX-RS runtime itself. One buggy documentation generation framework was generating ugly double-slashed resource links in case of leading slashes in @Path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With