Spring DI – Inner Beans Setter

Spring DI – Inner Beans Setter ”; Previous Next As you know Java inner classes are defined within the scope of other classes, similarly, inner beans are beans that are defined within the scope of another bean. Thus, a <bean/> element inside the <property/> or <constructor-arg/> elements is called inner bean and it is shown below. <?xml version = “1.0” encoding = “UTF-8”?> <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-3.0.xsd”> <bean id = “outerBean” class = “…”> <property name = “target”> <bean id = “innerBean” class = “…”/> </property> </bean> </beans> Example The following example shows a class TextEditor that can only be dependency-injected using pure setter-based injection. Let”s update the project created in Spring DI – Create Project chapter. We”re adding following files − TextEditor.java − A class containing a SpellChecker as dependency. SpellChecker.java − A dependency class. MainApp.java − Main application to run and test. Here is the content of TextEditor.java file − package com.tutorialspoint; public class TextEditor { private SpellChecker spellChecker; // a setter method to inject the dependency. public void setSpellChecker(SpellChecker spellChecker) { System.out.println(“Inside setSpellChecker.” ); this.spellChecker = spellChecker; } // a getter method to return spellChecker public SpellChecker getSpellChecker() { return spellChecker; } public void spellCheck() { spellChecker.checkSpelling(); } } Following is the content of another dependent class file SpellChecker.java − package com.tutorialspoint; public class SpellChecker { public SpellChecker(){ System.out.println(“Inside SpellChecker constructor.” ); } public void checkSpelling(){ System.out.println(“Inside checkSpelling.” ); } } Following is the content of the MainApp.java file − package com.tutorialspoint; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MainApp { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(“applicationcontext.xml”); TextEditor te = (TextEditor) context.getBean(“textEditor”); te.spellCheck(); } } Following is the configuration file applicationcontext.xml which has configuration for the setter-based injection but using inner beans − <?xml version = “1.0” encoding = “UTF-8”?> <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-3.0.xsd”> <!– Definition for textEditor bean using inner bean –> <bean id = “textEditor” class = “com.tutorialspoint.TextEditor”> <property name = “spellChecker”> <bean id = “spellChecker” class = “com.tutorialspoint.SpellChecker”/> </property> </bean> </beans> Output Once you are done creating the source and bean configuration files, let us run the application. If everything is fine with your application, it will print the following message − Inside SpellChecker constructor. Inside setSpellChecker. Inside checkSpelling. Print Page Previous Next Advertisements ”;

RxJava – Discussion

Discuss RxJava ”; Previous Next RxJava is a Java based extension of ReactiveX. ReactiveX is a project which aims to provide reactive programming concept to various programming languages. Reactive Programming refers to the scenario where program reacts as and when data appears. It is a event based programming concept and events can propagate to registers observers. As per the Reactive, they have combined the best of Observer pattern, Iterator pattern and functional pattern. The Observer pattern done right. ReactiveX is a combination of the best ideas from the Observer pattern, the Iterator pattern, and functional programming. Print Page Previous Next Advertisements ”;

Spring WS – Home

Spring Web Services Tutorial PDF Version Quick Guide Resources Job Search Discussion Spring Web Services (Spring-WS) is one of the project developed by the Spring Community. Its prime focus is to create document-driven Web Services. The Spring Web Services project facilitates contract-first SOAP service development, provides multiple ways to create flexible web services, which can manipulate XML payloads in multiple ways. Being Spring based, Spring Web Services uses Spring Concepts like Dependency Injection and Configurations seamlessly. Spring-WS requires Spring 3.0 version. Spring Framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003. This tutorial has been written based on the Spring Framework Version 4.1.6 released in March 2015. Audience This tutorial is designed for Java Programmers with a need to understand the Spring Web Services Framework in detail along with its architecture and actual usage. This tutorial will bring the readers to the intermediate level of expertise and from there they can take themselves to a higher level of proficiency. Prerequisites Before proceeding with this tutorial, you should have a good understanding of Java Programming Language. Additionally, understanding of the Eclipse IDE (Integrated Development Environment) is also required because all the examples have been compiled using the Eclipse IDE. Questions and Answers Spring Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations – Study Spring Questions and Answers Print Page Previous Next Advertisements ”;

XStream – Environment Setup

Xstream – Environment ”; Previous Next In this chapter, we will discuss on the different aspects of setting up a congenial environment for Java. Local Environment Setup If you want to set up your environment for Java programming language, then this section explains how to download and set up Java on your machine. Please follow the steps given below to set up you Java environment. Java SE can be downloaded for free from the link − Download Java. Follow the instructions to download Java and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set the environment variables to point to correct installation directories − Setting Up the Path for Windows 2000/XP Assuming you have installed Java in c:Program Filesjavajdk directory − Right-click on ”My Computer” and select ”Properties”. Click the ”Environment variables” button under the ”Advanced” tab. Alter the ”Path” variable so that it also contains the path to the Java executable. For example, if the path is currently set to ”C:WINDOWSSYSTEM32”, then change your path to read ”C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin”. Setting Up the Path for Windows 95/98/ME Assuming you have installed Java in c:Program Filesjavajdk directory − Edit the ”C:autoexec.bat” file and add the following line at the end − ”SET PATH = %PATH%;C:Program Filesjavajdkbin” Setting Up the Path for Linux, UNIX, Solaris, FreeBSD Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this. For example, if you use bash as your shell, then you would add the following line at the end of your ”.bashrc: export PATH=/path/to/java:$PATH” Popular Java Editors To write Java programs, you will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following − Notepad − On Windows, you can use any simple text editor like Notepad (Recommended for this tutorial) or TextPad. Netbeans − It is a Java IDE that is free and can be downloaded from https://www.netbeans.org/index.html. Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/. Download XStream Archive Download the latest version of XStream jar file from XStream download page. At the time of writing this tutorial, we have downloaded xstream-1.4.18.jar and copied it into C:>XStream folder. OS Archive name Windows xstream-1.4.18.jar Linux xstream-1.4.18.jar Mac xstream-1.4.18.jar Set XStream Environment Set the XStream_HOME environment variable to point to the base directory location where xstream jar is stored on your machine. The following table shows how to set the XStream environment on Windows, Linux, and Mac, assuming we”ve extracted xstream-1.4.18.jar in the XStream folder. Sr.No. OS & Description 1 Windows Set the environment variable XStream_HOME to C:XStream 2 Linux export XStream_HOME=/usr/local/XStream 3 Mac export XStream_HOME=/Library/XStream Set CLASSPATH Variable Set the CLASSPATH environment variable to point to the XStream jar location. The following table shows how to set the CLASSPATH variable on Windows, Linux, and Mac system, assuming we”ve stored xstream-1.4.18.jar in the XStream folder. Sr.No. OS & Description 1 Windows Set the environment variable CLASSPATH to %CLASSPATH%;%XStream_HOME%xstream-1.4.18.jar; 2 Linux export CLASSPATH=$CLASSPATH:$XStream_HOME/xstream-1.4.18.jar; 3 Mac export CLASSPATH=$CLASSPATH:$XStream_HOME/xstream-1.4.18.jar; Print Page Previous Next Advertisements ”;

XStream – Aliasing

XStream – Aliasing ”; Previous Next Aliasing is a technique to customize the generated XML or to use a particular formatted XML using XStream. Let’s suppose the following XML format is to be used to serialize/de-serialize the Student object. <student name = “Suresh”> <note> <title>first</title> <description>My first assignment.</description> </note> <note> <title>second</title> <description>My second assignment.</description> </note> </student> Based on the above XML format, let”s create model classes. class Student { private String studentName; private List<Note> notes = new ArrayList<Note>(); public Student(String name) { this.studentName = name; } public void addNote(Note note) { notes.add(note); } public String getName() { return studentName; } public List<Note> getNotes() { return notes; } } class Note { private String title; private String description; public Note(String title, String description) { this.title = title; this.description = description; } public String getTitle() { return title; } public String getDescription() { return description; } } Let”s test the above objects serialization using XStream. Create a java class file named XStreamTester in C:>XStream_WORKSPACEcomtutorialspointxstream. File: XStreamTester.java package com.tutorialspoint.xstream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.StaxDriver; public class XStreamTester { public static void main(String args[]) { XStreamTester tester = new XStreamTester(); XStream xstream = new XStream(new StaxDriver()); Student student = tester.getStudentDetails(); //Object to XML Conversion String xml = xstream.toXML(student); System.out.println(formatXml(xml)); } private Student getStudentDetails() { Student student = new Student(“Mahesh”); student.addNote(new Note(“first”,”My first assignment.”)); student.addNote(new Note(“second”,”My Second assignment.”)); return student; } public static String formatXml(String xml) { try { Transformer serializer = SAXTransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, “yes”); serializer.setOutputProperty(“{http://xml.apache.org/xslt}indent-amount”, “2”); Source xmlSource = new SAXSource(new InputSource( new ByteArrayInputStream(xml.getBytes()))); StreamResult res = new StreamResult(new ByteArrayOutputStream()); serializer.transform(xmlSource, res); return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray()); } catch(Exception e) { return xml; } } } class Student { private String studentName; private List<Note> notes = new ArrayList<Note>(); public Student(String name) { this.studentName = name; } public void addNote(Note note) { notes.add(note); } public String getName() { return studentName; } public List<Note> getNotes() { return notes; } } class Note { private String title; private String description; public Note(String title, String description) { this.title = title; this.description = description; } public String getTitle() { return title; } public String getDescription() { return description; } } Verify the Result Compile the classes using javac compiler as follows − C:XStream_WORKSPACEcomtutorialspointxstream>javac XStreamTester.java Now run the XStreamTester to see the result − C:XStream_WORKSPACEcomtutorialspointxstream>java XStreamTester Verify the output as follows − <?xml version = “1.0” encoding = “UTF-8″?> <com.tutorialspoint.xstream.Student> <studentName>Mahesh</studentName> <notes> <com.tutorialspoint.xstream.Note> <title>first</title> <description>My first assignment.</description> </com.tutorialspoint.xstream.Note> <com.tutorialspoint.xstream.Note> <title>second</title> <description>My Second assignment.</description> </com.tutorialspoint.xstream.Note> </notes> </com.tutorialspoint.xstream.Student> In the above result, the Student object name is fully qualified. To replace it as student tag, follow the next section. Class Aliasing Field Aliasing Implicit Collections Aliasing Attribute Aliasing Package Aliasing Print Page Previous Next Advertisements ”;

Spring Boot JPA – Overview

Spring Boot JPA – Overview ”; Previous Next What is JPA? Java Persistence API is a collection of classes and methods to persistently store the vast amounts of data into a database which is provided by the Oracle Corporation. Where to use JPA? To reduce the burden of writing codes for relational object management, a programmer follows the ‘JPA Provider’ framework, which allows easy interaction with database instance. Here the required framework is taken over by JPA. JPA History Earlier versions of EJB, defined persistence layer combined with business logic layer using javax.ejb.EntityBean Interface. While introducing EJB 3.0, the persistence layer was separated and specified as JPA 1.0 (Java Persistence API). The specifications of this API were released along with the specifications of JAVA EE5 on May 11, 2006 using JSR 220. JPA 2.0 was released with the specifications of JAVA EE6 on December 10, 2009 as a part of Java Community Process JSR 317. JPA 2.1 was released with the specification of JAVA EE7 on April 22, 2013 using JSR 338. JPA Providers JPA is an open source API, therefore various enterprise vendors such as Oracle, Redhat, Eclipse, etc. provide new products by adding the JPA persistence flavor in them. Some of these products include − Hibernate, Eclipselink, Toplink, Spring Data JPA, etc. Print Page Previous Next Advertisements ”;

XStream – Useful Resources

XStream – Useful Resources ”; Previous Next The following resources contain additional information on XStream. Please use them to get more in-depth knowledge on this topic. Useful Links on XStream XStream Wiki – Wikipedia reference for XStream library. Useful Books on XStream To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;

XStream – Annotations

XStream – Annotations ”; Previous Next XStream supports annotations similarly like automatic configuration instead of coding. In the previous chapter, we”ve seen the following configurations in code. xstream.alias(“student”, Student.class); xstream.alias(“note”, Note.class); xstream.useAttributeFor(Student.class, “studentName”); xstream.aliasField(“name”, Student.class, “studentName”); xstream.addImplicitCollection(Student.class, “notes”); The following code snippet illustrates the use of annotations to do the same work in a much easier way. @XStreamAlias(“student”) //define class level alias class Student { @XStreamAlias(“name”) //define field level alias @XStreamAsAttribute //define field as attribute private String studentName; @XStreamImplicit //define list as an implicit collection private List<Note> notes = new ArrayList<Note>(); @XStreamOmitField //omit a field to not to be a part of XML private int type; } Let us test the above annotation using XStream. Create a java class file named XStreamTester in C:>XStream_WORKSPACEcomtutorialspointxstream. File: XStreamTester.java package com.tutorialspoint.xstream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; import com.thoughtworks.xstream.annotations.XStreamImplicit; import com.thoughtworks.xstream.annotations.XStreamOmitField; import com.thoughtworks.xstream.io.xml.StaxDriver; public class XStreamTester { public static void main(String args[]) { XStreamTester tester = new XStreamTester(); XStream xstream = new XStream(new StaxDriver()); Student student = tester.getStudentDetails(); xstream.processAnnotations(Student.class); //Object to XML Conversion String xml = xstream.toXML(student); System.out.println(formatXml(xml)); } private Student getStudentDetails() { Student student = new Student(“Mahesh”); student.addNote(new Note(“first”,”My first assignment.”)); student.addNote(new Note(“second”,”My Second assignment.”)); student.setType(1); return student; } public static String formatXml(String xml) { try { Transformer serializer = SAXTransformerFactory.newInstance().newTransformer(); serializer.setOutputProperty(OutputKeys.INDENT, “yes”); serializer.setOutputProperty(“{http://xml.apache.org/xslt}indent-amount”, “2”); Source xmlSource = new SAXSource(new InputSource( new ByteArrayInputStream(xml.getBytes()))); StreamResult res = new StreamResult(new ByteArrayOutputStream()); serializer.transform(xmlSource, res); return new String(((ByteArrayOutputStream)res.getOutputStream()).toByteArray()); } catch(Exception e) { return xml; } } } @XStreamAlias(“student”) class Student { @XStreamAlias(“name”) @XStreamAsAttribute private String studentName; @XStreamImplicit private List<Note> notes = new ArrayList<Note>(); public Student(String name) { this.studentName = name; } public void addNote(Note note) { notes.add(note); } public String getName() { return studentName; } public List<Note> getNotes() { return notes; } @XStreamOmitField private int type; public int getType() { return type; } public void setType(int type) { this.type = type; } } @XStreamAlias(“note”) class Note { private String title; private String description; public Note(String title, String description) { this.title = title; this.description = description; } public String getTitle() { return title; } public String getDescription() { return description; } } Verify the Result Compile the classes using javac compiler as follows − C:XStream_WORKSPACEcomtutorialspointxstream>javac XStreamTester.java Now run the XStreamTester to see the result − C:XStream_WORKSPACEcomtutorialspointxstream>java XStreamTester Verify the output as follows − <?xml version = “1.0” encoding = “UTF-8”?> <student name = “Mahesh”> <note> <title>first</title> <description>My first assignment.</description> </note> <note> <title>second</title> <description>My Second assignment.</description> </note> </student> In order to instruct the XStream framework to process annotation, you need to add the following command before serializing xml. xstream.processAnnotations(Student.class); Or xstream.autodetectAnnotations(true); Print Page Previous Next Advertisements ”;

XStream – Overview

XStream – Overview ”; Previous Next XStream is a simple Java-based library to serialize Java objects to XML and vice versa. Features Easy to use − XStream API provides a high-level facade to simplify common use cases. No need to create mapping − XStream API provides default mapping for most of the objects to be serialized. Performance − XStream is fast and is of low memory footprint, which is suitable for large object graphs or systems. Clean XML − XStream produces clean and compact XML output that is easy to read. Object modification not required − XStream serializes internal fields like private and final fields, and supports non-public and inner classes. Default constructor is not a mandatory requirement. Full object graph support − XStream allows to maintain duplicate references encountered in the object-model and also supports circular references. Customizable conversion strategies − Custom strategies can be registered in order to allow customization of a particular type to be represented as XML. Security framework − XStream provides a fair control over unmarshalled types to prevent security issues with manipulated input. Error messages − When an exception occurs due to malformed XML, it provides detailed diagnostics to fix the problem. Alternative output format − XStream supports other output formats like JSON and morphing. Common Uses Transport − XML is a text representation of object and can be used to transport objects over the wire independent of the serialization / deserialization techniques used. Persistence − Objects can be persisted as XML in databases and can be marshalled/unmarshalled as and when required. Configuration − XML is self-explanatory and is heavily used to define configurations. Objects can also be used for configuration purpose after converting them to XML representation. Unit Tests − XStream API is JUnit compatible and can be used to enhance unit testing of application modules. Print Page Previous Next Advertisements ”;

Spring Batch – MySQL to XML

Spring Batch – MySQL to XML ”; Previous Next In this chapter, we will create a Spring Batch application which uses a MySQL reader and an XML Writer. Reader − The reader we are using in the application is JdbcCursorItemReader to read data from MySQL database. Assume we have created a table in the MySQL database as shown below − CREATE TABLE details.xml_mysql( person_id int(10) NOT NULL, sales VARCHAR(20), qty int(3), staffName VARCHAR(20), date VARCHAR(20) ); Assume we have inserted the following records in to it. mysql> select * from tutorialsdata; +————-+—————–+—————-+—————–+ | tutorial_id | tutorial_author | tutorial_title | submission_date | +————-+—————–+—————-+—————–+ | 101 | Sanjay | Learn Java | 06-05-2007 | | 102 | Abdul S | Learn MySQL | 19-04-2007 | | 103 | Krishna Kasyap | Learn JavaFX | 06-07-2017 | +————-+—————–+—————-+—————–+ 3 rows in set (0.00 sec) Writer − The Writer we are using in the application is StaxEventItemWriter to write the data to the XML file. Processor − The Processor we are using in the application is a custom processor which just prints the records read from the CSV file. jobConfig.xml Following is the configuration file of our sample Spring Batch application. In this file, we will define the Job and the Steps. In addition to these, we also define the beans for ItemReader, ItemProcessor, and ItemWriter. (Here, we associate them with their respective classes and pass the values for the required properties to configure them.) <beans xmlns = “http://www.springframework.org/schema/beans” xmlns:batch = “http://www.springframework.org/schema/batch” xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance” xmlns:util = “http://www.springframework.org/schema/util” xsi:schemaLocation = ” http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd”> <import resource = “../jobs/context.xml” /> <bean id = “report” class = “Report” scope = “prototype” /> <bean id = “itemProcessor” class = “CustomItemProcessor” /> <batch:job id = “helloWorldJob”> <batch:step id = “step1”> <batch:tasklet> <batch:chunk reader = “dbItemReader” writer = “mysqlItemWriter” processor = “itemProcessor” commit-interval = “10”> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <bean id = “dbItemReader” class = “org.springframework.batch.item.database.JdbcCursorItemReader” scope = “step”> <property name = “dataSource” ref = “dataSource” /> <property name = “sql” value = “select * from tutorials_data” /> <property name = “rowMapper”> <bean class = “TutorialRowMapper” /> </property> </bean> <bean id = “mysqlItemWriter” class = “org.springframework.batch.item.xml.StaxEventItemWriter”> <property name = “resource” value = “file:xml/outputs/tutorials.xml” /> <property name = “marshaller” ref = “reportMarshaller” /> <property name = “rootTagName” value = “Tutorial” /> </bean> <bean id = “reportMarshaller” class = “org.springframework.oxm.jaxb.Jaxb2Marshaller”> <property name = “classesToBeBound”> <list> <value>Tutorial</value> </list> </property> </bean> </beans> Context.xml Following is the context.xml of our Spring Batch application. In this file, we will define the beans like job repository, job launcher, and transaction manager. <beans xmlns = ” http://www.springframework.org/schema/beans” xmlns:jdbc = “http://www.springframework.org/schema/jdbc” 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-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd “> <!– stored job-meta in database –> <bean id = “jobRepository” class = “org.springframework.batch.core.repository.support.JobRepositoryFactoryBean”> <property name = “dataSource” ref = “dataSource” /> <property name = “transactionManager” ref = “transactionManager” /> <property name = “databaseType” value = “mysql” /> </bean> <bean id = “transactionManager” class = “org.springframework.batch.support.transaction.ResourcelessTransactionMana ger” /> <bean id = “jobLauncher” class = “org.springframework.batch.core.launch.support.SimpleJobLauncher”> <property name = “jobRepository” ref = “jobRepository” /> </bean> <!– connect to MySQL database –> <bean id = “dataSource” class = “org.springframework.jdbc.datasource.DriverManagerDataSource”> <property name = “driverClassName” value = “com.mysql.jdbc.Driver” /> <property name = “url” value = “jdbc:mysql://localhost:3306/details” /> <property name = “username” value = “myuser” /> <property name = “password” value = “password” /> </bean> <!– create job-meta tables automatically –> <jdbc:initialize-database data-source = “dataSource”> <jdbc:script location = “org/springframework/batch/core/schema-drop-mysql.sql” /> <jdbc:script location = “org/springframework/batch/core/schema-mysql.sql” /> </jdbc:initialize-database> </beans> CustomItemProcessor.java Following is the Processor class. In this class, we write the code of processing in the application. Here, we are printing the contents of each record. import org.springframework.batch.item.ItemProcessor; public class CustomItemProcessor implements ItemProcessor<Tutorial, Tutorial> { @Override public Tutorial process(Tutorial item) throws Exception { System.out.println(“Processing…” + item); return item; } } TutorialRowMapper.java Following is the TutorialRowMapper class which sets the data to the Tutorial class. import java.sql.ResultSet; import java.sql.SQLException; import org.springframework.jdbc.core.RowMapper; public class TutorialRowMapper implements RowMapper<Tutorial> { @Override public Tutorial mapRow(ResultSet rs, int rowNum) throws SQLException { Tutorial tutorial = new Tutorial(); tutorial.setTutorial_id(rs.getInt(“tutorial_id”)); tutorial.setTutorial_author(rs.getString(“tutorial_author”)); tutorial.setTutorial_title(rs.getString(“tutorial_title”)); tutorial.setSubmission_date(rs.getString(“submission_date”)); return tutorial; } } Tutorial.java Following is the Tutorial class. It is a simple Java class with setter and getter methods. In this class, we are using annotations to associate the methods of this class with the tags of the XML file. import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = “details”) public class Tutorial { int tutorial_id; String tutorial_author; String submission_date; @XmlAttribute(name = “tutorial_id”) public int getTutorial_id() { return tutorial_id; } public void setTutorial_id(int tutorial_id) { this.tutorial_id = tutorial_id; } @XmlElement(name = “tutorial_author”) public String getTutorial_author() { return tutorial_author; } public void setTutorial_author(String tutorial_author) { this.tutorial_author = tutorial_author; } @XmlElement(name = “tutorial_title”) public String getTutorial_title() { return tutorial_title; } public void setTutorial_title(String tutorial_title) { this.tutorial_title = tutorial_title; } @XmlElement(name = “submission_date”) public String getSubmission_date() { return submission_date; } public void setSubmission_date(String submission_date) { this.submission_date = submission_date; } public String toString() { return ” [Tutorial Id=” + tutorial_id + “, Tutorial Author =” + tutorial_author + “, Tutorial Title =” + tutorial_title + “, Submission Date =” + submission_date + “]”; } } App.java Following is the code which launces the batch process. In this class, we will launch the Batch Application by running the JobLauncher. import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main(String[] args) throws Exception { String[] springConfig = { “jobs/job_hello_world.xml” }; // Creating the application context object ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); // Creating the job launcher JobLauncher jobLauncher = (JobLauncher) context.getBean(“jobLauncher”); // Creating the job Job job = (Job) context.getBean(“helloWorldJob”); // Executing the JOB JobExecution execution = jobLauncher.run(job, new JobParameters()); System.out.println(“Exit Status : ” + execution.getStatus()); } } On executing this application, it will produce the following output. May 08, 2017 11:32:06 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3d646c37: startup date [Mon May 08 11:32:06 IST 2017]; root of context hierarchy May 08, 2017 11:32:06 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [jobs/job_hello_world.xml] May 08, 2017