3 Replies Latest reply on Sep 10, 2009 8:35 AM by Scott W. Ruch

    How to inject the result of a JNDI lookup?

    Scott W. Ruch Newbie


      Hopefully I haven't missed something obvious, I've been searching for a few hours for the answer to this, to no avail...

      In Spring, I would do this:




      java:comp/env/jms/ConnectionFactory




      How can I do this in the MC?


        • 1. Re: How to inject the result of a JNDI lookup?
          Scott W. Ruch Newbie

          Sorry, forgot to quote the XML snippet.

          "swruch" wrote:

          Hopefully I haven't missed something obvious, I've been searching for a few hours for the answer to this, to no avail...

          In Spring, I would do this:

          <property name="connectionFactory">
           <bean class="org.springframework.jndi.JndiObjectFactoryBean">
           <property name="jndiName">
           <value>java:comp/env/jms/ConnectionFactory</value>
           </property>
           </bean>
           </property>


          How can I do this in the MC?




          • 2. Re: How to inject the result of a JNDI lookup?
            Ales Justin Master

            Interestingly, it's exactly the same.
            See any -jboss-beans.xml, and just copy your snippet properly.

            Or you wanna know how to pull something out of JNDI?
            There is JNDIKernelRegistryPlugin that does that for you.
            You must simply add it as a bean.
            Note: it adds some performance penalty as once it's installed, it's included in every bean lookup

            • 3. Re: How to inject the result of a JNDI lookup?
              Scott W. Ruch Newbie

              Thanks, I was able to get it working with the JNDIKernelRegistryPlugin. I'm not using Spring here, so I prefer the native mechanism.

              For those who come looking for a solution, here's what it looks like. In this case, I'm injecting a DataSource that is bound as "java:/MySqlDS":

               <bean name="JndiKernelRegistryPlugin"
               class="org.jboss.kernel.plugins.dependency.JNDIKernelRegistryPlugin"/>
              
               <bean name="..." class="...">
              
               <property name="dataSource">
               <inject bean="java:MySqlDS"/>
               </property>