users@glassfish.java.net

Using CDI inside an OSGi bundle

From: <forums_at_java.net>
Date: Wed, 21 Sep 2011 11:46:15 -0500 (CDT)

 Sorry if a duplicate of this question is sent out - having issues with work
mail and need to get this to the group:

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?

 

--
Robert B. Weeks
--
[Message sent by forum member 'vaiism']
View Post: http://forums.java.net/node/845539