LibraryToggle FramesPrintFeedback

Another approach to using JNDI to get a reference to a JMS connection factory is to use the Spring framework's JndiTemplate bean. Using this approach, you configure an instance of the JndiTemple bean and then use the bean to perform all of your JNDI look-ups using a JndiObjectFactoryBean bean.

To get the JMS connection factory using a Spring JNDI template do the following:

  1. Add a bean element to your configuration for the JNDI template.

    1. Set the bean element's id attribute to a unique identifier.

    2. Set the bean element's class attribute to org.springframework.jndi.JndiTemplate.

    3. Add a property child element to the bean element.

      The property element will contain the properties for accessing the JNDI provider.

    4. Set the property element's name attribute to environment.

    5. Add a props child to the property element.

    6. Add a prop child element to the props element for each Java property needed to connect to the JNDI provider.

      A prop element has a single attribute called key whose value is the name of the Java property being set. The value of the element is the value of the Java property being set. Example 2.5 shows a prop element for setting the java.naming.factory.initial property.


      [Note]Note

      The properties you need to set will be determined by your JNDI provider. Check its documentation.

  2. Add a bean element to your configuration to retrieve the JMS connection factory using the JNDI template.

    1. Set the bean element's id attribute to a unique identifier.

    2. Set the bean element's class attribute to org.springframework.jndi.JndiObjectFactoryBean.

    3. Add a property child element to the bean element.

      This property element loads the JNDI template to be used for the look-up. You must set its name attribute to jndiTemplate. The value of its ref attribute is taken from the name attribute of the bean element that configured the JNDI template.

    4. Add a second property child element to the bean element.

      This property element specifies the JNDI name of the connection factory. You must set its name attribute to jndiTemplate.

    5. Add a value child element to the property element.

      The value of the element is the JNDI name of the connection factory.

Example 2.6 shows a configuration fragment for retrieving the WebSphere MQ connection factory using Sun's reference JNDI implementation.


Comments powered by Disqus