Search code examples
jakarta-eedependency-injectionejbjndilookup

inject ejb bean with mappedname in another bean without using name


I have a two ejb's in an EAR on glassfish, both implementing remote interfaces why they have both a mapped name assigned to them for client jndi lookup.

Now I want to inject one into the other. I successfully injected a Singleton Bean without any annotated name in my ejb's.
But this here is not working.

Is it necessary to do a JNDI lookup here, even when its local?

@Stateless(mappedName = "ChildBean")
public class ChildBean implements ChildBeanRemote {}

@Stateless(mappedName = "ParentBean")
public class ParentBean implements ParentBeanRemote
{
    @EJB
    private ChildBean childBean;
}

Solution

  • I think it should be

    @Stateless(mappedName = "ChildBean")
    public class ChildBean implements ChildBeanRemote {}
    
    @Stateless(mappedName = "ParentBean")
    public class ParentBean implements ParentBeanRemote
    {
        @EJB
        private ChildBeanRemote childBean; //You should use the interface and not the bean
    }