geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <>
Subject Re: @EJB 3.0 injection for non-servlet components
Date Thu, 13 Nov 2008 18:06:31 GMT

On Nov 13, 2008, at 9:37 AM, my_forum wrote:

> Guys,
> Probably this does not relate to Geronimo itself, but to OpenEjb but  
> this
> problem should be common for everybody who uses EJB 3.0 in Geronimo.
> So the questions is as follows:
> When I make the injection (StatesDAO is interface, StatesDAOBean is an
> implementation)
> @EJB
> private StatesDAO statesDAO;
> in the class that extends HttpServlet the injection works file, but  
> when I'm
> trying  to use the same code in my test methods (they are in the  
> Servlet
> Container) or in Struts Actions, the injection does not work not work.
> As a solution I tried to look up it by JNDI name but Always got
> NamingException
> new InitialContext().lookup("java:comp/env/StatesDAO")
> new InitialContext().lookup("java:comp/env/StatesDAOBean")
> new InitialContext().lookup("java:comp/env/myPackage.StatesDAO")
> new InitialContext().lookup("java:comp/env/myPackage.StatesDAOBean")
> Nothing works.
> So the second question is what is a correct JNDI name for my Bean?
> openejb-jar.xml does not contain any specific data, so the default  
> names are used.
> Thanks in advance!

Injection only works in components that the frameworks know about.   
So, servlets are known to the web container, ejbs known to the ejb  
container, and jsf beans to the jsf container.  However struts is not  
an annotation/injection aware framework/container.  You could switch  
to myfaces if you want to use injection.  Or you could inject the  
resources into your servlet and pass the references to the struts  

To use the java:comp/env jndi context you have to do something so the  
components are bound there: for ejbs this is either including a ejb- 
ref in web.xml or an @EJB annotation in some servlet in your web app.   
If you don't care about the java:comp/env context you can look in the  
geronimo log as the ejb app is starting up to see the jndi names the  
ejbs are bound under.  As Vamsi mentions you can also find these in  
the jndi viewer in the admin console.

david jencks

> -- 
> View this message in context:
> Sent from the Apache Geronimo - Users mailing list archive at  

View raw message