You can use a Spring configuration file to configure the following basic aspects of a router application:
Specify the Java packages that contain
RouteBuilder
classes.
Define routing rules in XML.
Configure components.
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.
Example 2.2. Basic Spring XML Configuration
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<package>my.package.name</package>
</camelContext>
</beans>Where the preceding configuration can be explained as follows:
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. | |
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. | |
Define a
| |
Use the
|
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]:
in your routing rules.QueueOrTopicName
Example 2.3. Configuring Components in Spring
<?xml version="1.0" encoding="UTF-8"?>
<beans ... >
<camelContext useJmx="true" xmlns="http://activemq.apache.org/camel/schema/spring">
<!-- Java packages (not shown) ... -->
</camelContext>
<!-- Configure the default ActiveMQ broker URL -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
</property>
</bean>
</beans>Where the preceding configuration can be explained as follows:
Use the
| |
When you set the property named,
| |
The connection factory property is initialized to be an instance of
| |
When you set the
|
For more details about configuring components in Spring, see Chapter 3, Components.