• Let’s assume that we have two entities, Author and Book. There is no materialized association between them, but, both entities shares an attribute named, genre. We want to use this attribute to join the tables corresponding to Author and Book, and fetch the result in a DTO. The result should…

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.oreilly.integration</groupId>
<artifactId>spring-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-integration</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>…

In this example, we’ll make the use of MessagingTemplate to send and receive the message.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.oreilly.integration</groupId>
<artifactId>spring-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-integration</name>
<description>Demo project for Spring Boot</description>…

In this example, we ‘ll make the use of Endpoint to send the message and Subscribe to it.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.oreilly.integration</groupId>
<artifactId>spring-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-integration</name>
<description>Demo project…

In this example, we’ll use the DirectChannel to subscribe to those channels.

PrintService.java

import java.util.Map.Entry;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

public class PrintService {

public void print(Message<String> message){
MessageHeaders headers = message.getHeaders();
for(Entry<String,Object> entry:headers.entrySet()){…

In this example, we’ll use Spring Integration basics — Message.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.oreilly.integration</groupId>
<artifactId>spring-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-integration</name>
<description>Demo project for Spring Boot</description>

<parent>…

In this exmple, we’ll see the basics of Spring Integration

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.oreilly.integration</groupId>
<artifactId>spring-integration-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-integration-demo</name>
<description>Demo project for Spring Boot</description>

<parent>…

In this example, we’ll validate the Job parameters, and accept those values in the Tasklet.

ParameterValidator.java — Exception for Job to signal that some JobParameters are invalid.

public class ParameterValidator implements JobParametersValidator {

@Override
public void validate(JobParameters jobParameters) throws JobParametersInvalidException {…

In this example, we’ll see the Spring Boot Security and JWT integration example. In this example I used below

  • Spring Boot v2.6.1
  • Spring Security
  • H2 DB
  • Lombok
  • Spring Data JPA
  • jjwt from io.jsonwebtoken

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>…

In this example, we’ll see how to make the call to REST API and feed that information into the reader.

Student.java

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class Student {
private String emailAddress;
private String name;
private String purchasedPackage;
}

SpringBatchJob.java

import org.springframework.batch.core.Job;
import…

Prateek Ashtikar

Java Developer and enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store