1 Reply Latest reply on Jul 12, 2018 9:33 AM by Greg Jewell

    Can not inject EJB into ManagedBean inside EAR

    Mustafa Kapdan Newbie

      Hi All,

       

      I try to deploy EJB EAR project on WildFly 10 / WildFly 13 versions, but both versions gives an error. You can find my project structure as summary.

      RemoteEJB bean could not be injected into ManagedBean, thats why I ended up with NullPointerException.

       

      ----WAR

      @ManagedBean(name = "ManagedBeanSample", eager = true)

      @ApplicationScoped

      public class ManagedBeanSample{

      @EJB

      private ParamEJBRemote paramEJBRemote; // Which gives NPE, I tried to inject with full path but not work. ( @EJB(lookup="java:global/......")

      @PostConstruct

      public void init() {

      // CALL EJB

      paramEJBRemote.doSmthg();

      }

      }

       

      ---EJBClient

      @Remote

      public interface ParamEJBRemote {

                doSmthg();

      }

       

      ----EJB

      @Stateless

      @TransactionManagement(value=TransactionManagementType.BEAN)

      @TransactionAttribute(value=TransactionAttributeType.NEVER)

      @Remote(ParamEJBRemote.class)

      public class ParamEJB implements ParamEJBRemote, ParamEJBLocal {


      public void doSmthg() {

      }

      }

       

       

       

      Do you have any solutions to solve this problem?

       

      Have a nice day?

       

      Best Regards

        • 1. Re: Can not inject EJB into ManagedBean inside EAR
          Greg Jewell Apprentice

          Have you tried removing the @Remote annotation from the ParamEJB class?  Since it's implementing an interface that is also annotated with @Remote, annotating the class isn't needed.  Also, are you sure the lookup you are providing is actually the lookup that wildfly is assigning to the bean?  I've seen cases where people expect the lookup to be slightly different than what it actually is, and don't check the server.log file to see what it really is.