Java – is it possible to define a Jax RS service interface separate from its implementation (using eclipse and Jersey)?

I don't know if the title is confusing, but let's say I have this interface:

@Produces(MediaType.APPLICATION_JSON)
@Path("/user")
public interface UserService {

    @GET
    @Path("/{userId}")
    public Response getUser(@PathParam("userId") Long userId);

}

Why when I try to implement a version of eclipse to override annotated override methods, but not for classes@ H_ 403_ 5@

class UserServiceImpl implements UserService {

    @Override
    @GET
    @Path("/{userId}")
    public Response getUser(@PathParam("userId") Long userId) {
        // TODO Auto-generated method stub
        return null;
    }

}

I'm trying to create a standard definition for rest web services, and then have different implementations Can I use standard Jax RS? Do I have any chance to use wrong comments@ H_ 403_ 5@

Solution

Annotation inheritance can only be used when no Jax RS annotation is used on the implementation class: it is described in section 3.6 of jsr-339

You redefine @ path and @ produces for the method, but not for the class@ H_ 403_ 5@

So the path annotation in your code should be on the specific class: @ h_ 403_ 5@

public interface UserService {

    @GET
    @Path("/{userId}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getUser(@PathParam("userId") Long userId);

}


@Path("/user")
class UserServiceImpl implements UserService {

    @Override
    @GET
    @Path("/{userId}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getUser(@PathParam("userId") Long userId) {
        // TODO Auto-generated method stub
        return null;
    }

}

BTW, the specification encourages us to copy the comments of specific classes: @ h_ 403_ 5@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>