LibraryLink ToToggle FramesPrintFeedback

Spring Configuration

You can use a Spring configuration file to configure the following basic aspects of a router application:

In addition to these core aspects of router configuration, you can of course take advantage of the generic Spring mechanisms for configuring and linking together Java objects within the Spring container.

The Spring configuration file for your router application must be stored at the following location, relative to your CLASSPATH:

META-INF/spring/camel-context.xml

Example 2.2, “Basic Spring XML Configuration” shows a basic Spring XML configuration file that instantiates and activates RouteBuilder classes defined in the my.package.name Java package.


Where the preceding configuration can be explained as follows:

1

This line specifies the location of the Spring framework schema. The URL should represent a real, physical location from where you can download the schema. The version of the Spring schema currenlty supported by Mediation Router is Spring 2.0.

2

This line specifies the location of the Camel context schema. The URL shown in this example always points to the latest version of the schema.

3

Define a camelContext element, which belongs to the namespace, http://activemq.apache.org/camel/schema/spring.

4

Use the package element to specify one or more Java package names. As it starts up, the Spring wrapper automatically instantiates and activates any RouteBuilder classes that it finds in the specified packages.

To configure router components, use the generic Spring bean configuration mechanism (which implements a dependency injection configuration pattern). That is, you define a Spring bean element to create a component instance, where the class attribute specifies the full class name of the relevant Mediation Router component. Bean properties on the component class can then be set using the Spring properties element. Using the dependency injection mechanism, it is relatively straightforward to figure what properties you can set by consulting the JavaDoc for the relevant component.

Example 2.3, “Configuring Components in Spring” shows how to configure a JMS component using Spring configuration. This component configuration enables you to access endpoints of the format jms:[queue|topic]:QueueOrTopicName in your routing rules.


Where the preceding configuration can be explained as follows:

1

Use the class attribute to specify the name of the component class—in this example, we are configuring the JMS component class, JmsComponent. The id attribute specifies the prefix to use for JMS endpoint URIs. For example, with the id equal to jms you can connect to an endpoint like jms:queue:FOO.BAR in your application code.

2

When you set the property named, connectionFactory, Spring implicitly calls the JmsComponent.setConnectionFactory() method to initialize the JMS component at run time.

3

The connection factory property is initialized to be an instance of ActiveMQConnectionFactory (that is, an instance of a FUSE Message Broker message queue).

4

When you set the brokerURL property on ActiveMQConnectionFactory, Spring implicitly calls the setBrokerURL() method on the connection factory instance. In this example, the broker URL, vm://localhost, specifies a broker that is co-located in the same Java Virtual Machine (JVM) as the router.The broker library automatically instantiates the new broker as soon as you try to send a message to it.

For more details about configuring components in Spring, see Chapter 3, Components.