RESTeasy如何解决@Path冲突

发布于 2024-10-01 10:11:58 字数 377 浏览 0 评论 0原文

考虑上面的代码

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

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

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

请求 http://host/a/a 我总是得到“b”。

选择适当方法的策略是什么? 有什么方法可以了解通往不同资源的多个路径吗?

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 paths to diferent resources ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2024-10-08 10:11:58

根据评论进一步编辑,

我不知道 RESTEasy 中是否有任何报告工具可以提供跨一系列带注释的服务类的重复匹配模式列表。但是,您可以使用以下方法之一解决此问题:

  1. grep 和 awk @Path 的源代码以生成路径表达式的可排序列表
  2. 使用 AnnotationReader 实现 作为单元测试的一部分扫描您的类路径并让它检测重复的正则表达式模式。

编辑以更好地定位问题

RESTEasy 使用 基于正则表达式的路径系统并选择最接近匹配的模式。如果发生碰撞,将使用最后一个匹配的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文