4 Replies Latest reply on Mar 7, 2012 12:39 PM by Viacheslav Krot

    EJB2 beans and jndi ENC problems

    Viacheslav Krot Newbie

      Hi everybody,

       

      I'm trying to migrate old EJB2-based application from weblogic to jboss 7.1 and can't overcome problems with jndi-lookups.

      I want to make beans available under names 'ejb/BeanName'. I mimicked one of unit-tests - https://github.com/jbossas/jboss-as/tree/master/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/ejb2/reference/eararchive that does exactly what I need, but still get an error.

      I have a bean OrdersBean that gets CustomersBean like that:

      InitialContext context = new InitialContext();
      Context env = (Context)context.lookup("java:/comp/env");
      CustomersBean o = (CustomersBean)env.lookup("ejb/CustomersBean"); 
      

       

      and  get an error:

       

      javax.naming.NameNotFoundException: comp/env/ejb/CustomersBean -- service jboss.naming.context.java.comp.env.ejb.CustomersBean
      

       

       

      My ejb-jar.xml is:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar 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/ejb-jar_3_0.xsd"
                version="3.0">
                <display-name>EJB TEST</display-name>
                <enterprise-beans>
                          <session>
                                    <ejb-name>CustomersBean</ejb-name>
                                    <home>com.pls.CustomersHome</home>
                                    <remote>com.pls.CustomersBean</remote>
                                    <ejb-class>com.pls.CustomersEJB</ejb-class>
                                    <session-type>Stateless</session-type>
                                    <transaction-type>Container</transaction-type>
                          </session>
        
                          <session>
                                    <ejb-name>OrdersBean</ejb-name>
                                    <home>com.pls.OrdersHome</home>
                                    <remote>com.pls.OrdersBean</remote>
                                    <ejb-class>com.pls.OrdersEJB</ejb-class>
                                    <session-type>Stateless</session-type>
                                    <transaction-type>Container</transaction-type>
                                    <ejb-ref>
                                              <ejb-ref-name>ejb/CustomersBean</ejb-ref-name>
                                              <ejb-ref-type>Session</ejb-ref-type>
                                              <home>com.pls.CustomersHome</home>
                                              <remote>com.pls.CustomersBean</remote>
                                    </ejb-ref>
                          </session>
                </enterprise-beans>
      </ejb-jar>
      
      

       

      jboss-ejb3.jar is:

       

      <?xml version="1.0"?>
      <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
                xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd
                           http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
                version="3.1" impl-version="2.0">
                <enterprise-beans>
      
      
                          <session>
                                    <ejb-name>OrdersBean</ejb-name>
                                    <ejb-ref>
                                              <ejb-ref-name>ejb/CustomersBean</ejb-ref-name>
                                              <jndi-name>java:module/CustomersBean!com.pls.CustomersBean</jndi-name>
                                    </ejb-ref>
                          </session>
        
                </enterprise-beans>
      </jboss:ejb-jar>
      
      

       

      Application is deployed as single jar, and I still get an error:

       

      javax.naming.NameNotFoundException: comp/env/ejb/CustomersBean -- service jboss.naming.context.java.comp.env.ejb.CustomersBean
      

       

      What could causes the problem?

       

      Thank you in advance.

        • 1. Re: EJB2 beans and jndi ENC problems
          Viacheslav Krot Newbie

          oh, completely forgot to include jboss output during deployment:

           

          17:58:35,836 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named CustomersBean in deployment unit deployment "myejbs.jar" are as follows:

           

           

                  java:global/myejbs/CustomersBean!com.pls.CustomersBean

                  java:app/myejbs/CustomersBean!com.pls.CustomersBean

                  java:module/CustomersBean!com.pls.CustomersBean

                  java:jboss/exported/myejbs/CustomersBean!com.pls.CustomersBean

                  java:global/myejbs/CustomersBean!com.pls.CustomersHome

                  java:app/myejbs/CustomersBean!com.pls.CustomersHome

                  java:module/CustomersBean!com.pls.CustomersHome

                  java:jboss/exported/myejbs/CustomersBean!com.pls.CustomersHome

           

           

          17:58:35,840 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named OrdersBean in deployment unit deployment "myejbs.jar" are as follows:

           

           

                  java:global/myejbs/OrdersBean!com.pls.OrdersHome

                  java:app/myejbs/OrdersBean!com.pls.OrdersHome

                  java:module/OrdersBean!com.pls.OrdersHome

                  java:jboss/exported/myejbs/OrdersBean!com.pls.OrdersHome

                  java:global/myejbs/OrdersBean!com.pls.OrdersBean

                  java:app/myejbs/OrdersBean!com.pls.OrdersBean

                  java:module/OrdersBean!com.pls.OrdersBean

                  java:jboss/exported/myejbs/OrdersBean!com.pls.OrdersBean

           

          Btw, jboss version is jboss 7.1 Final

          • 2. Re: EJB2 beans and jndi ENC problems
            Viacheslav Krot Newbie

            One more note: same example code works just fine under JBoss 6.1.0 Final, with one change in jboss-ejb3.xml - jndi-name changed from java:module/CustomersBean!com.pls.CustomersBean to java:/CustomersBean

             

            How can I make this work under AS 7.1?

             

             


            • 3. Re: EJB2 beans and jndi ENC problems
              jaikiran pai Master

              Context env = (Context)context.lookup("java:/comp/env");

               

              Change this to:

               

              Context env = (Context)context.lookup("java:comp/env");

               

              Notice the difference?

              • 4. Re: EJB2 beans and jndi ENC problems
                Viacheslav Krot Newbie

                Yes! This worked, that you a lot!