Enterprise Java

Spring Integration: A lightweight integration Approach

Today’s application expects access of all business in enterprise environment regardless of application technologies, which require, seamless integration with desperate systems. This integration can be achieved through wiring of desperate systems using Middleware technologies.

Integration platform enables environment for applications to share information with each other to make architecture high interoperable. Spring Integration provides a mediation framework to build lightweight integration solution using routing and mediation, regardless of protocols. The Spring Integration is lightweight routing and mediation framework and doesn’t need heavy weight ESB container to deploy.

Spring Integration uses Message object to communicate, route and pass the data, which is nothing, but a wrapper on Java object consists of payload and header. Payload consist data which could be any type such as File, String, stream etc. and header consist generic information on message such as id, timestamp etc.

Message communicates to producer via channel, which decoupled source from destination and post the message to any protocols such as JMS, HTTP, Ldap, file etc. Producers send Messages to a channel, and consumers receive Messages from a channel


Simple Integration Application

Below example show how producer send an employee object to channel and publisher receive message from channel.

Spring Dependency Maven configuration

For starting simple integration example we just need to add the core spring integration and spring context dependency to maven pom.xml. Moreover we also need Junit and spring test to enable unit testing


Spring Configuration
We have to configure channel and gateway in spring configuration to send and receive message


<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd">
 <context:component-scan base-package="org.springsample.integration"/>
 <gateway id="request" service-interface="org.springsample.integration.SentRequest"/>
 <channel id="sendRequest"/>
 <outbound-channel-adapter channel="sendRequest" ref="receiveResponse" method="processMessage" />

Here we created request gateway to send the message to channel and outbound adapter to receive message from the sendRequest channel. Gateway of Spring Integration is entry points to send messages, which specify using Java Interface. Spring Integration automatically define proxy implementation at runtime

Request and Receive

Below we create the SentRequest and ReceiveResponse class to send and receive message as follows


package org.springsample.integration;
import org.springframework.integration.annotation.Gateway;
public interface SentRequest {
 public void process(Employee emp);


@Gateway annotation will indicate entry point to send message

package org.springsample.integration;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.MessageEndpoint;
public class ReceiveResponse {
public void processMessage(Message<Employee> message) {
 Employee employee = message.getPayload();
 System.out.println("Message Received \n Name :"+employee.getName()+"/n Phone : "+employee.getPhone()+"/n Address :"+employee.getAddress());


@MessageEndpoint will indicate that it will receive message from channel via adapter.

Not but not leas below is Employee POJO

package org.springsample.integration;
public class Employee {
 private String name;
 private String title;
 private String address;
 private String phone;

public Employee(String name, String phone, String address) {this.name=name;this.phone=phone; this.address=address;
//……..Getter amd Setter


We can test this using spring test framework as below

package org.springbyexample.integration;
public class SpringIntegTest {
 private SentRequest request = null;
 public void testIntegration() {
 Employee emp = new Employee("John", "12345678", "Sunny Street Mac RG1");

Make sure you keep spring config file name SpringIntegTest-context in org/springbyexample/integration and should be in your class path
While running SpringIntegTest, it will display console message as follows

Message Received
Name :John/n Phone : 12345678/n Address :Sunny Street Mac RG1


Spring Integration is open source simple integration that enhances loose coupling and make application integration easy and simpler. It will integrate, route and mediate the message across the channel and gateway in configurable way. This article helps to understand about Spring Integration and will aid you to develop a simple integration application.



Nitin Kumar

Nitin Kumar works as a Software Architect , predominately focus on Agile, TDD, Service Oriented Architecture, Grails and JEE. Besides working in software development, He writes technical articles and watches and studies new technologies
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Eric Shiau
Eric Shiau
10 years ago

Please update source code download link. Link is broken.

10 years ago
Reply to  Eric Shiau

I have published it again thanks for notifying me.

9 years ago

Nice example for beginners. Thank you.

9 years ago

Hello Nitin,

I am trying to run the Spring Integration Example.
Do we need to run it through JUnit or a Web Application.


8 years ago

With respect to example explained above, what is the main advantage of using spring integration here? We can do this task by getting a bean of processor class and calling its process method.
Please provide your suggestion. This question really eating my head.

Back to top button