Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
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:
- Add the following namespace declaration to your
beanselement in your service unit's configuration.xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jee="http://www.springframework.org/schema/jee"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add a
jee:jndi-lookupelement to your service unit's configuration.Thejee:jndi-lookupelement has two attributes. They are described in Table 14.4, “Attributes for Using Spring's JEE JNDI Lookup”. - Add a
jee:environmentchild element to thejee:jndi-lookupelement.Thejee:environmentelement 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
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:
- Add a
beanelement to your configuration for the JNDI template.- Set the
beanelement'sidattribute to a unique identifier. - Set the
beanelement'sclassattribute toorg.springframework.jndi.JndiTemplate. - Add a
propertychild element to thebeanelement.Thepropertyelement will contain the properties for accessing the JNDI provider. - Set the
propertyelement'snameattribute toenvironment. - Add a
propschild to thepropertyelement. - Add a
propchild element to thepropselement for each Java property needed to connect to the JNDI provider.Apropelement has a single attribute calledkeywhose 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 apropelement 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>
<prop key="java.naming.factory.initial"> com.sun.jndi.fscontext.RefFSContextFactory </prop>Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe properties you need to set will be determined by your JNDI provider. Check its documentation.
- Add a
beanelement to your configuration to retrieve the JMS connection factory using the JNDI template.- Set the
beanelement'sidattribute to a unique identifier. - Set the
beanelement'sclassattribute toorg.springframework.jndi.JndiObjectFactoryBean. - Add a
propertychild element to thebeanelement.Thispropertyelement loads the JNDI template to be used for the look-up. You must set itsnameattribute tojndiTemplate. The value of itsrefattribute is taken from thenameattribute of thebeanelement that configured the JNDI template. - Add a second
propertychild element to thebeanelement.Thispropertyelement specifies the JNDI name of the connection factory. You must set itsnameattribute tojndiTemplate. - Add a
valuechild element to thepropertyelement.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