이 콘텐츠는 선택한 언어로 제공되지 않습니다.

14.2. Using JNDI


Overview

Many JMS providers store a reference to their connection factory in a JNDI service to ease retrieval. Red Hat JBoss Fuse allows developers to choose between a straight JNDI look-up and using Spring JNDI templates. Which mechanism you choose will depend on your environment.

Spring JEE JNDI lookup

Spring provides a built-in JNDI look-up feature that can be used to retrieve the connection factory for a JMS provider. To use the built-in JNDI look-up do the following:
  1. Add the following namespace declaration to your beans element in your service unit's configuration.
    xmlns:jee="http://www.springframework.org/schema/jee"
    Copy to Clipboard Toggle word wrap
  2. Add a jee:jndi-lookup element to your service unit's configuration.
    The jee:jndi-lookup element has two attributes. They are described in Table 14.4, “Attributes for Using Spring's JEE JNDI Lookup”.
    Expand
    Table 14.4. Attributes for Using Spring's JEE JNDI Lookup
    AttributeDescription
    id Specifies a unique identifier by which the JMS endpoints will reference the connection factory.
    jndi-name Specifies the JNDI name of the connection factory.
  3. Add a jee:environment child element to the jee:jndi-lookup element.
    The jee:environment element contains a collection of Java properties that are used to access the JNDI provider. These properties will be provided by your JNDI provider's documentation.
Example 14.4, “Getting the WebLogic Connection Factory Using Spring's JEE JNDI Look-up” shows a configuration snippet for using the JNDI look-up with WebLogic.

Example 14.4. Getting the WebLogic Connection Factory Using Spring's JEE JNDI Look-up

<beans xmlns:jee="http://www.springframework.org/schema/jee" ... >
  ...
  <jee:jndi-lookup id="connectionFactory" jndi-name="weblogic.jms.XAConnectionFactory">
    <jee:environment>
      java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
      java.naming.provider.url=t3://localhost:7001
    </jee:environment>
  </jee:jndi-lookup>
  ...
</beans>
Copy to Clipboard Toggle word wrap

Spring JNDI Templates

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 14.5, “Setting a Java Property” shows a prop element for setting the java.naming.factory.initial property.

      Example 14.5. Setting a Java Property

      <prop key="java.naming.factory.initial">
        com.sun.jndi.fscontext.RefFSContextFactory
      </prop>
      Copy to Clipboard Toggle word wrap
      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 14.6, “Using a JNDI Template to Look Up a Connection Factory” shows a configuration fragment for retrieving the WebSphere MQ connection factory using Sun's reference JNDI implementation.

Example 14.6. Using a JNDI Template to Look Up a Connection Factory

<beans ... >
  ...
  <bean id="jndiTemplate"
        class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
      <props>
        <prop key="java.naming.factory.initial">
          com.sun.jndi.fscontext.RefFSContextFactory
        </prop>
        <prop key="java.naming.provider.url">
          file:/tmp/
        </prop>
      </props>
    </property>
  </bean>

  <bean id="connectionFactory"
        class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate"
              ref="jndiTemplate" />
    <property name="jndiName">
      <value>MQConnFactory</value>
     </property>
  </bean>
  ...
</beans>
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat