Skip to main content

Using Spring configuration

Spring is an application development framework for enterprise Java. Apache Camel is designed to work nicely with the Spring Framework. The Route designer of Talend Studio allows you to add a Spring context to a Route for configuration purpose. You can define beans and resources in Spring XML DSL and then use them in Routes. This makes it possible for developers to combine Java and Spring codes in the configuration of Routes. It is particularly useful when there is no explicit component available in the palette.

To be able to use the Spring configuration, your knowledge of Spring is required. For more information about Spring, see Spring website. For the Spring support of Apache Camel, see Apache Camel documentation.

To add a Spring context to a Route, you need first to create the Route. For more information about how to create a Route, see Creating a Route Creating a Route.

The Spring tab is located in the lower half of the design workspace. When you create a Route in the design workspace, a default Spring configuration is set in the Spring view.

Spring view.

By default, the Apache Camel JMX Notification is declared in the Spring configuration. You can configure it as needed and call it in the Route. For more information about Apache Camel JMX Notification, see Apache Camel documentation.

Enter the code you want to implement in this view. The following example shows using a bean to call a previously defined Route Resource named RouteWithSpring:

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="location" value="classpath:RouteWithSpring.properties"/>
</bean>

To define a Spring bean of ActiveMQComponent in Route builder, use the following code:

<bean id="activemq" class="org.apache.camel.component.activemq.ActiveMQComponent"> 
    <property name="brokerURL" value="tcp://localhost:61616"/> 
    <property name="username" value="xxx"/> 
    <property name="password" value="xxx"/>
</bean>

The following code gives another example that defines a message routing from the endpoint vm:a to log:vm:

<camel:camelContext>
	<camel:route>
		<camel:from uri="vm:a" />
		<camel:to uri="log:vm" />
	</camel:route>
</camel:camelContext>

For more information about creating and using Route Resources, see Using Route Resources.

When you export a Route, the Spring XML file will be also exported in the KAR file.

Click the Restore Default button to change back to the default Spring configuration.

For a real-life use case of how to use Spring configuration in a Route, see the scenario provided for cSEDA in SEDA (Mediation).

Information noteWarning:

When the Spring configuration is wrong, the Route may fail to start.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!