Wednesday, September 7, 2011

Getting Started With Spring batch 2.0

Hello world example using spring batch 2.0

Hello world example with spring batch 2.0 along with eclipse.
Follow below steps to start the hello world example with spring batch.

Step 1 : open eclipse - create new java project.
Step 2 : create new xml file under project (applicationContext.xml)
Step 3: create one more xml. under project location.(simpleJob.xml)
Step 4: create one java class which implements
org.springframework.batch.core.step.tasklet.Tasklet
Step 5: override the required methods in your respective class.
Step 6: we can run the job through
org.springframework.batch.core.launch.support.CommandLineJobRunner
This class will take two parameters (Job path and job parameters).
We need to pass those details.
Step 7: Here i am posting, how to run through eclipse.
Right click on the java class( Which we written)- Select RunConfigurations -
Select Main tab- Select Main class as
org.springframework.batch.core.launch.support.CommandLineJobRunner
Click on Arguments - Enter Jobpath and JobParameters under Program arguments
Eg: simpleJob.xml helloWorldJob
Click on the Run Button then hello world will display on the console.

Step 8: Required jar files
commons-logging-1.1.1.jar
javaee-api-5.0-1.jar
log4j-1.2.14.jar
spring-2.5.6.jar
spring-batch-core-2.1.8.RELEASE.jar
spring-batch-infrastructure-2.1.8.RELEASE.jar
spring-beans-2.5.6.jar
spring-context-2.5.6.jar
spring-core-2.5.6.jar
spring-tx-2.5.6.jar
xstream-1.3.1.jar

In this way you can start the Spring batch.

Source Code of applicationContext.xml




 

 class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
   
  
 
    
  
  
Source Code of simpleJob.xml









Source Code of HelloWorld.java
package com.siva;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class HelloWorld implements Tasklet {
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
System.out.println("Hello World");
return RepeatStatus.FINISHED;
}
} 
Source Code of the log4j.properties

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c{1} %x - %m%n
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.springframework=DEBUG
log4j.logger.org.springframework.security.ldap=DEBUG

Tuesday, May 10, 2011

Split the big String into words

//This method used to split the big text and add it to the next line
public String StringSplit( String text , int splitSize)
{

String finalString = "";
String dummyString =text;
for(int i=0;i<=text.length()/splitSize;i++)
{
if(dummyString.length()>=splitSize)
{
finalString+= dummyString.substring(0,splitSize) +"\n";
dummyString = dummyString.substring(splitSize);
}
else
finalString+= dummyString;

}
return finalString;
}

Tuesday, April 27, 2010

webservices

Web services definition.
The term webservices is simply defined as serve a request through web is known as web
service. The service can be of any type.
the term Web Services refers to the technologies that allow for making connections.
Services are what you connect together using Web Services. A service is the endpoint of a
connection.

Thursday, March 11, 2010

Spring

What is spring and Why spring So popular?

spring is open source frame work.
spring is so popular because spring is very loosley coupled, easily maintainable,
less coding, good security etc.

spring components are as follows.
Spring IOC, AOP, ORM, Web, MVC,DAO,spring context
these components are also called as spring modules.

AddToAny

Contact Form

Name

Email *

Message *