Spring Book – Chapter 20 – Spring Integration

JDBC

Enterprise applications require some sort of interaction with a database; Spring Integration provides solution to address this with ease. The JDBC channel adapters support sending and receiving messages via database queries. Spring JDBC supports HyperSQL databse by default. We will configure the base “datasource” bean using this database and using “jdbc” Spring namespace as shown in Listing 22-52 below.

Listing 22-52. Declaring datasource bean in Spring configuration file

Listing 22-53 below shows maven dependency required for integrating JDBC using Spring Integration.

Listing 22-53. Maven dependency required

Listing 22-54 below shows configuration of main Spring Integration namespace and JDBC related namespace in the Spring configuration file (jdbc-integration-context.xml).

Listing 22-54. Spring Integration Namespace declaration

Listing 22-55 shows configuring JDBC inbound channel adapter that uses a poller and datasource configured in previous code listing.

Listing 22-55. Configuring JDBC inbound channel adapter with a poller

Listing 22-56 below shows configuring JDBC outbound channel adapter that uses datasource configured earlier.

Listing 22-56. Configuring JDBC outbound channel adapter

The outbound Gateway is like a combination of the outbound and inbound adapters: its role is to handle a message and use it to execute a SQL query and then respond with the result sending it to a reply channel. Listing 22-57 shows configuring JDBC outbound gateway.

Listing 22-57. Configuring JDBC outbound gateway in Spring configuration file

If you would like to execute stored procedure and stored function, plain JDBC support will not suffice. Spring Integration providers following components to support this as follows:

  • Stored Procedure Inbound Channel Adapter (Listing 22-58)
  • Stored Procedure Outbound Channel Adapter (Listing 22-59)
  • Stored Procedure Outbound Gateway (Listing 22-60)

Listing 22-58. Configuring Stored Procedure Inbound Channel Adapter

Listing 22-59. Configuring Stored Procedure Outbound Channel Adapter

Listing 22-60. Configuring Stored Procedure Outbound Gateway

Page Visitors: 11711

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Hi,
    Thanks for this blog and information sharing!
    I have one question from Spring Integration. Just thought of checking with you.
    I have SimplewebserviceOutBoundGateway. I need to send a document / attachment to the webservice. How will i achieve that?
    This is my current gateway configuration:

    Please let me know, if you can throw some light in this area.
    Thanks in Advance!

  2. Hi,
    Thank you for your information sharing.
    I have one doubt,could you please suggest me the correct frameworks to address that issue.

    My requirement is I would like to get and process files using spring and camel.

    Thanks,
    Madhu