开发者

How RESTeasy solves @Path conflict

开发者 https://www.devze.com 2023-01-24 06:29 出处:网络
Consider the code above @Path(\"a\") @Produces(\"text/plain\") public class A { @GET @Path(\"a\") public String getA() {

Consider the code above

@Path("a")
@Produces("text/plain")
public class A {

    @GET
    @Path("a")
    public String getA() {
        return "a";
    }

    @GET
    @Path("a")
    public String getB() {
        return "b";
    }
}

Requesting http://host/a/a i always get "b".

What is the strategy to select the appropiated method ? Any way to get informed about multiple p开发者_如何转开发aths to diferent resources ?


Further edited in light of the comment

I don't know of any reporting tool within RESTEasy that offers a list of duplicated matching patterns across a range of annotated service classes. However, you could approach this problem using one of the following methods:

  1. grep and awk the source code for @Path to generate a sortable list of path expressions
  2. Use an AnnotationReader implementation to scan over your classpath as part of a unit test and have it detect duplicated regex patterns.

Edited to better target the question

RESTEasy uses a regex based system for paths and selects the most closely matching pattern. In the event of a collision the last one matched is used.

0

精彩评论

暂无评论...
验证码 换一张
取 消