【问题标题】:WARNING: The (sub)resource method contains empty path annotation警告:(子)资源方法包含空路径注释
【发布时间】:2016-02-04 11:07:23
【问题描述】:

我已经配置了像“/v1/”这样的休息路径和像“/test/”这样的servlet中配置的端点。

现在我从 java 类“Test”中删除了“/v1”。

org.glassfish.jersey.internal.Errors logErrors
WARNING: The following warnings have been detected: WARNING: The (sub)resource method test in com.abc.services.Test contains empty path annotation.

进行此更改后,我收到了上述警告。如何处理这个警告?

而且我希望这个“/v1”删除跨 10 个休息路径的更改。所以有人帮我在没有警告的情况下跑步吗?

【问题讨论】:

    标签: java rest jersey jetty jersey-2.0


    【解决方案1】:

    警告意味着您有一个使用@Path("/")@Path("") 注释的资源方法。比如

    @Path("test")
    public class Test {
    
        @GET
        @Path("/")
        public String test(){}
    }
    

    不知道泽西岛为什么会发出警告,也许只是为了确保那是你真正想要的。原因是带有@Path("/") 的资源方法是多余的,因为如果你只是这样做就已经暗示了

    @Path("test")
    public class Test {
    
        @GET
        public String test(){}
    }
    

    没有@Path("/")。它的工作原理相同。因此,如果您有这些,请将它们删除,它应该会消除警告。

    【讨论】:

    • 谢谢@peeskillest。它现在可以在没有警告的情况下工作。
    • 谢谢。但不适用于类级别注释,在这种情况下需要“/”。
    猜你喜欢
    • 2017-09-08
    • 2016-04-29
    • 2014-10-27
    • 2021-05-19
    • 1970-01-01
    • 2016-11-02
    • 2017-07-29
    • 1970-01-01
    • 2015-04-29
    相关资源
    最近更新 更多