users@jersey.java.net

Pass interfaces to a resource class

From: Max Hajek <wickedoldlunatic_at_gmail.com>
Date: Thu, 18 Mar 2010 17:00:22 +0100

Hi,

this is probably a relatively stupid question, but bear with me, I'm new to
JAX-RS and the general world of writing webservices with Java (although I've
been doing completely different Java stuff for years). I've googled a lot,
but not really found a clear explanation, so now I use this medium and annoy
your ;>

How can I pass interfaces to resource classes?
E.g., if I got a class

@Path("/services")
public class Service {
    private SomeDependency dependency;

    @Path("/register")
    @GET
    @Produces("text/plain")
    public String getSomething() {
        return dependency.getSomething();
    }
}

where SomeDependency is an interface
interface SomeDependency {
    String getSomething();
}

How could I pass a concrete implementation of SomeDependency into Service
instances constructed on the fly?

Many thanks,
Max