5 Replies Latest reply on Jan 20, 2013 9:12 AM by skeldol

    Problem with Resource Reference Mapping

    skeldol

      I am using JBoss 7.1in Eclipse.

       

      I have some code in an EJB:

       

         
      Context initCtx = new InitialContext();
        
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
        
      // Look up our value



        
      jndiValue = (String) envCtx.lookup("test");   

       

      I have an jboss-ejb3.xml with the following in it:

                  <ejb-name>SimpleJNDILookUpBean</ejb-name>

                  <resource-ref>

                      <res-ref-name>env/test</res-ref-name>

                      <jndi-name>java:global/my/jndi/key</jndi-name>

                  </resource-ref>

       

       

      I though this would map by ejb jndi look-up to the correct jndi look-up but I get:

       

      20:41:56,234 ERROR [stderr] (EJB default - 6) javax.naming.NameNotFoundException: env/test -- service jboss.naming.context.java.comp.SimpleJNDILookUpBean.SimpleJNDILookUpBean.SimpleJNDILookUpBean.env.test

       

      Which suggests the mapping is not happening.  Can anyone help?

        • 1. Re: Problem with Resource Reference Mapping
          jaikiran

          By default, the resource references are bound to java:comp/env/ namespace. With your configuration:

           

          <res-ref-name>env/test</res-ref-name>

          you managed to prefix another "env" to it. So either you have to lookup java:comp/env/env/test or change the res-ref-name to just "test":

           

          <res-ref-name>test</res-ref-name>

           

          and look it up as java:comp/env/test

          • 2. Re: Problem with Resource Reference Mapping
            mitvivek

            Hi Jaikiran,

             

            In respect to the original question, I had a DS initially created by the jndi name: jdbc/TestDS.

             

            But in Jboss the naming convention for the same needs to be somewhat like java:/jdbc/TestDS.

             

            Could you please tell me how shall I look this DS in my application? Shall this be still through "jdbc/TestDS" or shall this be "java:/jdbc/TestDS"

             

            Thanks

            Vivek

            • 3. Re: Problem with Resource Reference Mapping
              skeldol

              Thanks.  I actually got it working using the resource ref java:comp/env/test.  Now you've solved the full mystery for me.

              • 4. Re: Problem with Resource Reference Mapping
                jaikiran

                Vivek, please create a separate thread for your question.

                • 5. Re: Problem with Resource Reference Mapping
                  skeldol

                  Hi

                   

                  Can I ask another question?  In my EJB when I do the JNDI look-up I've written "java:comp/env/test". What I'd like to know is are the jndi look-ups from within an EJB under a specific namespace?  I'd assumed based on the above they would be under java:comp/env, but if I do a look-up on test this is not mapped in the resource ref.  I then figured it was directly under java but a look-up on comp/env/test also does map.  Can you help on this too please?

                   

                  Thanks

                  Leon