1 Reply Latest reply on Jun 14, 2011 3:41 AM by Alexander Hartner

    Upgrading from 4.2.3 to 5.1 fails with "Unable to inject jndi dependency"

    Alexander Hartner Expert

      We are in the process of upgrading from JBoss 4.2.3 to Jboss 5.1. However when we deploy our applications EAR file we get the following error:

       

      javax.ejb.EJBException: java.lang.RuntimeException: Unable to inject jndi dependency: 
                     env/jms/ConnectionFactory into property com.abc.AbstractManagedBean.m_factory: jms not bound
              at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
              at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
              at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      
      

       

      Within the ejb-jar.xml file I declare the reference to the connection factory as follows:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar version="3.0" 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">
          <description>ABC EJB</description>
          <display-name>ABCEJB</display-name>
          <enterprise-beans>
      
      
              <!-- JobRequest Listener MDB -->
              <message-driven>
                  <ejb-name>JobRequestListener</ejb-name>
                  <ejb-class>com.abc.backend.jobs.JobRequestListener</ejb-class>
                  <message-destination-link>JobRequests</message-destination-link>
                  <!--Inherited From AbstractManagedBean -->
                  <resource-ref>
                      <res-ref-name>jms/ConnectionFactory</res-ref-name>
                      <res-type>javax.jms.ConnectionFactory</res-type>
                      <res-auth>Container</res-auth>
                  </resource-ref>
      ...
      

       

      which I then map to the in jboss.xml to the actual JNDI name as follows:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <jboss
              xmlns="http://www.jboss.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_5_1.xsd"
              version="5.1">
          <enterprise-beans>
      
              <!-- Job Request Listener MDB -->
              <message-driven>
                  <ejb-name>JobRequestListener</ejb-name>
                  <destination-jndi-name>queue/abc/JobRequests</destination-jndi-name>
                  <!--Inherited From AbstractManagedBean -->
                  <resource-ref>
                      <res-ref-name>jms/ConnectionFactory</res-ref-name>
                      <res-type>javax.jms.ConnectionFactory</res-type>
                      <jndi-name>ConnectionFactory</jndi-name>
                  </resource-ref>
      ...
      

       

      Since it is trying to resolve jms I get the impression that the jboss.xml file is completely ignored. I already tried changing the xml schema declaration to both the 5.0 and 5.1 schema. The 5.1 schema produces other XML errors which I managed to work around. At this stage the problem occurs using either schema. I did check the JNDI View under JMX-Console to verify that the Connection Factory exists under the Global JNDI Namespace.

        • 1. Re: Upgrading from 4.2.3 to 5.1 fails with "Unable to inject jndi dependency"
          Alexander Hartner Expert

          The problem was that I also included a JMS Connection factory within my ear file. I was using the xml descriptor to declare the JMS connection factory used by some of my EJBs. By adding a dependency for each bean which uses the connection factory to the jboss.xml deployment descriptor I managed to work around this issue.

           

          There are some things which made this more confusing that it has to be.

           

          1.) The error mentions jms/ConnectionFactory rather than my custom connection factory. This is rather misleading. It could have been much simpler to determine the cause of the problem if it told me that my custom connection factory was not found

           

          2.) The startup sequence / order has been changed from 4.2.3 to 5.1.

           


                  <!-- Job Request Listener MDB -->
                  <message-driven>
                      <ejb-name>JobRequestListener</ejb-name>
                      <destination-jndi-name>queue/abc/JobRequests</destination-jndi-name>
                      <!--Inherited From AbstractManagedBean -->

                      <resource-ref>
                          <res-ref-name>jms/ConnectionFactory</res-ref-name>
                          <res-type>javax.jms.ConnectionFactory</res-type>
                          <jndi-name>ConnectionFactory</jndi-name>
                      </resource-ref>

          ...

                    <depends>jboss.jca:service=ConnectionFactoryBinding,name=jms/ABCJMSConnectionFactory</depends>

                  <message-driven>