-
1. Re: EJB injection returns null
jamesjoh Oct 30, 2009 6:17 PM (in response to h.haveman)Shouldn't
if (landen == null) { LOG.info("LandBean landen is null"); }
beif (landHandler == null) { LOG.info("LandBean landen is null"); }
Not sure if it's just a transcription error but your code posted to the forum is checking if the uninitialized List is null.
That said, I'm not sure if Injection works into a managed bean. -
2. Re: EJB injection returns null
h.haveman Oct 30, 2009 6:41 PM (in response to h.haveman)Thanks,
that did the trick. That's code completion in an IDE for you, without looking closely which variable to pick. I can now access the session bean using jndi lookup, however injecting the bean using the @EJB annotaion still results in a NULL object. But at least I can use the bean now.
Henk -
3. Re: EJB injection returns null
meetoblivion Oct 30, 2009 7:44 PM (in response to h.haveman)LandBean itself is not a managed object. @EJB injection only works on managed objects, JSF components, servlets, and EJBs.
-
4. Re: EJB injection returns null
meetoblivion Oct 30, 2009 7:47 PM (in response to h.haveman)ah sorry i read it wrong.
can you provide some of the configuration on the Remote? and the implementation? either deployment desc or annotations? -
5. Re: EJB injection returns null
h.haveman Oct 30, 2009 8:04 PM (in response to h.haveman)The injected bean is a stateless session bean. This bean is deployed as a part of an ear.
When I perform a jndi lookup in jmx-console I can see it is there. Also when deploying the ear
I can see messages of the bean being added to jndi.00:15:52,472 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI: ear/LandBean/remote - EJB3.x Default Remote Business Interface ear/LandBean/remote-mx.business.land.LandRemote - EJB3.x Remote Business Interface ear/LandBean/local - EJB3.x Default Local Business Interface ear/LandBean/local-mx.business.land.LandLocal - EJB3.x Local Business Interface
The code of the bean ispackage mx.business.land; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import mx.model.Land; @Stateless public class LandBean implements LandLocal, LandRemote { @PersistenceContext(unitName = "mx") private EntityManager em; @SuppressWarnings("unchecked") public List<Land> getAll() { Query query = em.createQuery("from Land"); List<Land> rtrn = query.getResultList(); return rtrn; } public Land getById(String pCode) { Land rtrn = em.find(Land.class, pCode); return rtrn; } }
Everything works fine if I do a jndi lookup, but using injection with the @EJB annotation gives me a null object. In my code I now check if the injection succeeded. If not I use jndi lookup. This works for me, but it would be much nicer if injection always succeeded.
Henk -
6. Re: EJB injection returns null
meetoblivion Oct 30, 2009 9:50 PM (in response to h.haveman)unless you have an ejb-jar that's overriding it, remove the name attribute in your client.
e.g.@EJB(mappedName = "ear/LandBean/remote") private LandRemote landHandler;
-
7. Re: EJB injection returns null
h.haveman Oct 31, 2009 5:44 AM (in response to h.haveman)I tried it, but it makes no difference. The bean is still null.
-
8. Re: EJB injection returns null
jaikiran Oct 31, 2009 10:02 AM (in response to h.haveman)You probably are not using the 2.5 xsd version in your web.xml. You need this:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
-
9. Re: EJB injection returns null
h.haveman Oct 31, 2009 5:51 PM (in response to h.haveman)I am using the 2.5 xsd in my web.xml, so that's not causing it.