users@glassfish.java.net

Using CDI inside an OSGi bundle

From: Robert Weeks <RWeeks_at_ext-inc.com>
Date: Wed, 21 Sep 2011 09:12:06 -0700

Hello -

I am having a few issues and was hoping for some insight.

If I have an OSGi bundle (a jar bundle deployed via /autodeploy/bundles), and within I declare a bean:

@Stateless
public class MyTestBean {
 ...

I can see this via normal @EJB injection (within the same bundle) if using a container controlled class such as an MDB (@MessageDriven).

But - if I am wanting to use CDI to be able to inject these resources into other classes that are not container controlled - such as:

public class MyTestClass {
   @Inject
    MyTestBean myBean;

shouldn't I be able to do this outside of container controlled classes within the bundle?

I have set the 'beans.xml' inside the META-INF folder within the bundle jar.

I can see this work in the controlled classes such as the MDB if I replace the @EJB MyTestBean with @Inject MyTestBean - but I cannot get a hold of it in any of my other POJOs.

Is this how it is supposed to work? Are we not able to see these injections either within a bundle?

Thanks for any thoughts.


Robert Weeks
Lead Developer - Framework and UI
EXTENSION, INC.
Email: rweeks_at_ext-inc.com
Office: 260-797-0200 x4228
General: 877-207-3753
www.OpenTheRedBox.com

Download the FREE EXTENSION Mobile App for iPhone and iPod Touch
http://www.opentheredbox.com/iPhone_appDemo.php

Download the FREE EXTENSION Mobile App for Android-Based Devices
https://market.android.com/details?id=com.ext_inc.android&feature=search_result

We're Exhibiting in an Area Near You
http://www.opentheredbox.com/events.php