Jersey @Path annotation required at class level

I have a class like:

public class TestService {

@Path("/v1/test1/list")
    public Response getTest1() {
}

@Path("/v1/test2/list")
    public Response getTest2() {
}

}

If I do not give @Path annotation at the class level, then this class is not recognized as a REST resource, but I cannot give the path "/ v1" for this class, since there is another class with @Path ("/ v1").

What is a workaround for this class to be recognized by the Rest resource

+4
source share
2 answers

Resource classes

A @Pathannotation is required to determine the resource class. Quoting Jersey documentation :

POJO ( Java), @Path, , @Path , @GET, @PUT, @POST, @DELETE.

Justas, @Path("") TestService. :

@Path("")
public class TestService {

    @GET
    @Path("/v1/test1/list")
    public Response getTest1() {
        ...
    }

    @GET
    @Path("/v1/test2/list")
    public Response getTest2() {
        ...
    }
}

, , , , , :

@Path("/v1/test1")
public class TestService1 {

    @GET
    @Path("/list")
    public Response getTest1() {
        ...
    }
}
@Path("/v1/test2")
public class TestService2 {

    @GET
    @Path("/list")
    public Response getTest2() {
        ...
    }
}
+4

@Path("") @Path("/"). , -.

+2

Source: https://habr.com/ru/post/1653070/


All Articles