Skip to main content

@Inject bean into EJB

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

Hi

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

@Stateless
class TestBean {
@Inject
private TestDao testDao;
...
}

class TestDao {
...
}

Am I missing something?

Thanks
Alex

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=http://www.dominikdorn.com]Dominik Dorn[/url]

Tausche Deine [url=http://www.studyguru.eu] Lernunterlagen [/url] auf
[url=http://www.studyguru.eu]Study Guru[/url]!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

ksak
Offline
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.

szczyp

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?

evx
Offline
Joined: 2008-02-19
Points: 0

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


Thanks a lot!