Skip to main content

@Inject bean into EJB

4 replies [Last post]
Joined: 2008-02-19
Points: 0


I am trying to inject a bean (DAO) into an EJB but it does not seam to work. I am using GlassFish 3.0.

class TestBean {
private TestDao testDao;

class TestDao {

Am I missing something?


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Dominik Dorn

You are mixing containers.

either make TestBean ApplicationScoped or inject the DAO with @EJB

[url=]Dominik Dorn[/url]

Tausche Deine [url=] Lernunterlagen [/url] auf
[url=]Study Guru[/url]!

To unsubscribe, e-mail:
For additional commands, e-mail:

Joined: 2005-05-20
Points: 0

What do you mean by "mixing containers"? Using CDI within an EJB component is fine. The thing to double-check is that the module in which the bean is packaged has a beans.xml file. Otherwise, CDI is not enabled for that module.


Do you have META-INF/beans.xml in your ejb jar? Other than that, the classes are package private, so their default constructors are too. I am not sure if this gets in the way or not.
What is the exception / erroneous behaviour that you experience? I am doing the very same thing that you do and it works for me. But my DAOs and the EJB are in the same jar file, maybe yours are in different jars?

Joined: 2008-02-19
Points: 0

An empty META-INF/beans.xml did the job.

Thanks a lot!