spring batch work

This commit is contained in:
eugenp 2015-12-28 18:23:13 +02:00 committed by David Morley
parent 69e2394d4b
commit c8d9bd4f21
13 changed files with 22 additions and 17 deletions

View File

@ -12,7 +12,11 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>spring-batch-intro</name> <name>spring-batch</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
@ -15,8 +15,14 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures> </natures>

View File

@ -1,13 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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">
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> <modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId> <groupId>org.baeldung</groupId>
<artifactId>spring-batch-intro</artifactId> <artifactId>spring-batch</artifactId>
<version>0.1-SNAPSHOT</version> <version>0.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>spring-batch-intro</name> <name>spring-batch</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
<properties> <properties>

View File

@ -4,31 +4,27 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App { public class App {
public static void main(String[] args) { public static void main(final String[] args) {
// Spring Java config // Spring Java config
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(SpringConfig.class); context.register(SpringConfig.class);
context.register(SpringBatchConfig.class); context.register(SpringBatchConfig.class);
context.refresh(); context.refresh();
// Spring xml config // Spring xml config
// ApplicationContext context = new ClassPathXmlApplicationContext( // ApplicationContext context = new ClassPathXmlApplicationContext("spring-batch.xml");
// "spring-batch-intro.xml");
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); final JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("firstBatchJob"); final Job job = (Job) context.getBean("firstBatchJob");
System.out.println("Starting the batch job"); System.out.println("Starting the batch job");
try { try {
JobExecution execution = jobLauncher.run(job, new JobParameters()); final JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Job Status : " + execution.getStatus()); System.out.println("Job Status : " + execution.getStatus());
System.out.println("Job succeeded"); System.out.println("Job succeeded");
} catch (Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Job failed"); System.out.println("Job failed");
} }