Hi Max,
There are a number of solutions:
1) Use Java EE 6 and CDI;
http://blogs.sun.com/arungupta/entry/totd_124_using_cdi_jpa
2) Use Guice, and Jersey's Guice integration.
https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
3) Use Jersey's own injection support.
4) Use Spring and Jersey's Spring integration.
https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/package-summary.html
My recommendations:
- If you want a solution that works with many EE 6 technologies choose
1) in conjunction with GlassFish v3.
- If you want a general minimal solution choose 2.
- If you want a tightly focused solution with limited dependencies
choose 3.
I can supply more details as required,
Paul.
On Mar 18, 2010, at 5:00 PM, Max Hajek wrote:
> 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