users@glassfish.java.net

Re: Using CDI inside an OSGi bundle

From: Sahoo <sanjeeb.sahoo_at_ORACLE.COM>
Date: Thu, 22 Sep 2011 09:55:33 +0530

CDI allows injection into non-component classes, but the instances must
still be created by CDI. Your activator is instantiated by OSGi
framework and CDI has no way to hook into that process. You can
programmatically get hold of the CDI injection manager and request an
instance from it instead of using @Inject in your main class.


On Thursday 22 September 2011 09:19 AM, forums_at_java.net wrote:
> Hi Sahoo -
>
> In this context - MyTestClass is the main class of the bundle (created
> within
> the activator actually). So I couldn't really instantiate it as an
> injection
> itself.
>
> I thought CDI allowed the ability to make most pojo's injectable into not
> only managed classes - but other pojo's as well (which are @Default by
> default - no)?. Seems this must not be the case.
>
> I am wanting to create some resource/jms/producer beans that can be
> injected
> into the main class (MyTestClass). MyTestClass in this case is also
> registered as an OSGi service that is used via declarative service in
> other
> places.
>
> Thanks for the response.
>
> --
>
> Robert B. Weeks
>
>
> --
>
> [Message sent by forum member 'vaiism']
>
> View Post: http://forums.java.net/node/845539
>
>