5 Replies Latest reply on Jul 31, 2006 1:33 AM by joo

    @EJB DI in a servlet always null

    joo Newbie

      I work with jboss 4.0.4 and tried to install a statless session bean.
      The bean is deployed.
      But in a servlet, the DI doesn't work. It is allways null.
      There is no error message,....

      1. I think, I tried all possibilities. What can be wrong?
      2. I tried to get the bean with lookup. But the JNDI name is not ok.
      How can I get the right JNDI name of the bean ?

      thanks
      Georg


        • 1. Re: @EJB DI in a servlet always null
          Frank Stolle Newbie

          Currently you cannot use the @EJB-annotation in servlets. It is only available in SessionBeans and MDBs.

          You should try to look via JNDIView (JMX-Console -> JNDIView -> list-Method) for your SessionBean to know the correct name.

          • 2. Re: @EJB DI in a servlet allways null
            joo Newbie

            Thanks!
            Now it works fine.

            Georg

            • 3. Re: @EJB DI in a servlet always null
              joo Newbie

              I thought it works :-(

              I deployed EJBs:

              06:24:10,431 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=esLoginBean, class=at.joo.ejb.session.main.ESLoginBean, type=STATELESS
              06:24:10,431 INFO [Ejb3Deployment] EJB3 deployment time took: 31
              06:24:10,447 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,jar=joo-ejb-1.0.jar,name=esLoginBean with dependencies:
              06:24:10,572 INFO [EJB3Deployer] Deployed: file:/D:/Server/jboss-4.0.4RC1/server/default/deploy/joo-ejb-1.0.jar


              JNDIView in jboss gives following output



              java: Namespace
              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
              +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
              +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
              +- comp (class: javax.naming.Context)
              +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
              +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
              +- jaas (class: javax.naming.Context)
              | +- other (class: org.jboss.security.plugins.SecurityDomainContext)
              | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
              | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
              | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
              +- timedCacheFactory (class: javax.naming.Context)
              Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
              +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
              +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
              +- comp.ejb3 (class: javax.naming.Context)
              | NonContext: null
              +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
              +- TransactionManager (class: org.jboss.tm.TxManager)

              Global JNDI Namespace
              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
              +- UserTransactionSessionFactory (proxy: $Proxy30 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
              +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
              +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
              +- HAPartition (class: org.jnp.interfaces.NamingContext)
              | +- DefaultPartition (class: org.jboss.ha.framework.server.HAPartitionImpl)
              +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
              +- topic (class: org.jnp.interfaces.NamingContext)
              | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
              | +- testTopic (class: org.jboss.mq.SpyTopic)
              | +- securedTopic (class: org.jboss.mq.SpyTopic)
              +- queue (class: org.jnp.interfaces.NamingContext)
              | +- A (class: org.jboss.mq.SpyQueue)
              | +- testQueue (class: org.jboss.mq.SpyQueue)
              | +- ex (class: org.jboss.mq.SpyQueue)
              | +- DLQ (class: org.jboss.mq.SpyQueue)
              | +- D (class: org.jboss.mq.SpyQueue)
              | +- C (class: org.jboss.mq.SpyQueue)
              | +- B (class: org.jboss.mq.SpyQueue)
              +- esLoginBean (class: org.jnp.interfaces.NamingContext)
              | +- remote (proxy: $Proxy50 implements interface at.joo.ejb.session.i.main.EILogin,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
              +- HASessionState (class: org.jnp.interfaces.NamingContext)
              | +- Default (class: org.jboss.ha.hasessionstate.server.HASessionStateImpl)
              +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
              +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
              +- jmx (class: org.jnp.interfaces.NamingContext)
              | +- invoker (class: org.jnp.interfaces.NamingContext)
              | | +- RMIAdaptor (proxy: $Proxy29 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
              | +- rmi (class: org.jnp.interfaces.NamingContext)
              | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
              +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
              +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)


              In a servlet I need the EJB. I deployed a persistence jar and a war file, no ear.
              Please, can you give me the correct Statement for the lookup methode, to get the esLoginBean/remote.

              thanks
              Georg

              • 4. Re: @EJB DI in a servlet always null
                Carlo de Wolf Master

                Please try:

                InitialContext ctx = new InitialContext();
                EILogin login = (EILogin) ctx.lookup("esLoginBean/remote");


                • 5. Re: @EJB DI in a servlet always null
                  joo Newbie

                  Thanks,
                  yes, now it works :-)

                  I had a second bug in the JNDI configuration.