WARNING: The (sub)resource method contains empty p

2019-06-14 22:00发布

问题:

I have configured rest path like "/v1/" and the endpoint configured in servlet like '/test/'.

Now I removed the "/v1" from the java class "Test".

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.

I got the above warning after make this change. How to handle this warning?

And I want this "/v1" removing changes for across 10 rest paths. So anyone help me to run without warnings?

回答1:

The warning means you have a resource method annotated with @Path("/") or @Path(""). For instance

@Path("test")
public class Test {

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

Not sure why Jersey would give a warning, maybe just to make sure that's what you really want. The reason is that a resource method with @Path("/") is redundant, as it's already implied if you were just to do

@Path("test")
public class Test {

    @GET
    public String test(){}
}

without the @Path("/"). It works the same. So if you have these, remove them, and it should take away the warnings.