users@jersey.java.net

[Jersey] Re: Using _at_Inject in Jersey

From: Robert DiFalco <robert.difalco_at_gmail.com>
Date: Sun, 9 Mar 2014 10:47:58 -0700

No, MyService is an interface so it is the contract. MyServiceImp is the
implementation of MyService. So for example if you had a Spring
ApplicationContext you could even make that Spring Bean instance injectable
like this:

     register( applicationCtx.getBean( MyService.class ), MyService.class );

Make sense? In this case I'm binding a specific instance of MyService.class
(a Bean instance) to the MyService interface contract.



On Sat, Mar 8, 2014 at 8:17 PM, Ivan Li <email2liyang_at_gmail.com> wrote:

> should be bind( MyService.class ).to( MyServiceImpl.class );
>
> right?
>
> Best regards,
> Ivan
>
> On 3/9/14, 1:07 AM, Robert DiFalco wrote:
>
> Answering my own question here:
>
> Don't use register in RestConfig. Instead create an AbstractBinder with
> the service to inject.
>
> register( new AbstractBinder() {
> @Override
> protected void configure() {
> bind( MyServiceImpl.class ).to( MyService.class );
> }
> });
>
>
>
> On Fri, Mar 7, 2014 at 2:45 PM, Robert DiFalco <robert.difalco_at_gmail.com>wrote:
>
>> How do I make a service available for injection with Jersey 2.6?
>>
>> I simply want to have something like:
>>
>> @Inject
>> private MyService service;
>>
>> In a resource. I assumed in my configuration I could just do this:
>>
>> register( MyService.class );
>>
>> But apparently that doesn't work. What's the simplest way to make
>> MyResource @Inject-able with MyService in 2.6?
>>
>> TIA!
>>
>> R.
>>
>
>
>