Results 1 to 3 of 3

Thread: Sample usage of jndi-lookup

  1. #1

    Default Sample usage of jndi-lookup

    I need to lookup a JMS connection factory from jndi
    and inject the connection factory into another bean
    (a JMS Template).

    I can do this manually in Java; however, I'd like
    to use j2ee:jndi-lookup bean configuration support.

    I am not clear on how to use this from the Appendix
    A2.3.1 of Spring tutorial.

    This is what I have:

    Code:
      <bean 
            id="jmsFactory"
    		class="org.apache.activemq.ActiveMQConnectionFactory"
                      p:brokerURL="tcp://localhost:61616"
        />
     
        <bean 
    	id="messageDispatchTemplate"
    		class="org.springframework.jms.core.JmsTemplate"
    		   p:connectionFactory-ref="jmsFactory"
        />
    I would like to convert this to something like (I hope):

    Code:
       <jee:jndi-lookup id="jmsFactory" jndi-name="jms/AmqConnectionFactory"/>
    
       <bean 
    	id="messageDispatchTemplate"
    		class="org.springframework.jms.core.JmsTemplate"
    		   p:connectionFactory-ref="jmsFactory"
        />
    I am assuming that the syntax I have given the second snippet above
    is approximate - if this syntax would work as is, I'd be delighted;
    of course, in this case, I would like to know how Spring figures
    out the type of "jmsFactory".

    Any suggestions?

    Thanks,

    /U

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    The type is determined at injection-time, it tries to cast/convert the jmsFactory to the correct type. On the jee:jndi-lookup you can also specify an proxy-interface so then it will (also) try to check the type when doing the lookup.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2004
    Location
    Fareham, England
    Posts
    313

    Default

    Hi umark

    I have updated the relevant section of the Spring reference documentation with some examples of dependency injecting the value of the 'jee:jndi-lookup' bean... hopefully it is clearer now.

    Cheers
    Rick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •