如果我有两条相同的路径但其中一条有参数,在 Jersey 中的行为是什么?

What is the behaviour in Jersey if I have two equal paths but one has a parameter?

我想知道如果我在泽西岛有两个 @PUT 服务并且其中一个定义为:

会发生什么
@PUT
@Path("/{elementId}")

另一个是:

@PUT
@Path("/service")

预期的行为是什么?

鉴于所有其他内容都相同(即内容协商注释等),鉴于您提供的内容,如果您访问 /service 路径,将始终命中显式 @Path("/service")

在匹配算法[1]中,排序候选方法的主键是路径表达式。 @Path("/service")多(对方有none),所以总是赢。您应该能够轻松测试此行为。

[1]:3.7.2 Request Matching (in the JAX-RS spec。上面指定的部分是2.f(class级别@Path注解也一样,在1.e中)