Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

How to access client in Resource request #12

Closed
jensenbox opened this issue Apr 6, 2016 · 1 comment
Closed

How to access client in Resource request #12

jensenbox opened this issue Apr 6, 2016 · 1 comment

Comments

@jensenbox
Copy link

Would be awesome to show exactly how to access a client instance from within a resource.

Is the prescribed method to add a parameter to the init function for the resource with the client or is there some way to do a wrapper like "@context" to grab the client?

@joschi
Copy link
Member

joschi commented Apr 6, 2016

@jensenbox You can either simply add the Client instance to the constructor parameters of your JAX-RS resource class and pass the Client instance on instantiation of that class (e. g. in the Application#run() method) or use HK2 to inject the Client instance into your resource class via the @Inject annotation.

See https://gist.github.com/joschi/f706e394172988f9200b for an example of how to do the latter.

@joschi joschi closed this as completed Apr 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants