Hi Friends,
I am trying to load the bean-definition for spring-batch & spring-hadoop dynamically at run time not at the time of starting the application. The application load the bean-definition at any time and invoke the spring-batch job. Problem is while running it using CommandLineJobRunner it is working fine but while running it pragmatically it is throwing some error.
When I run a spring-batch-job ( ie mapreduce jobs ) using mvn command line it works fine for me. -
Code:mvn exec:java -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner -Dexec.args="context3.xml secondJob"
But when I try to run progamatically it got the error -
Error I got -Code:mvn exec:java -Dexec.mainClass="org.test.SecondExample"
Code:12/07/04 13:55:07 INFO support.SimpleJobLauncher: Job: [FlowJob: [name=secondJob]] launched with the following parameters: [{programatic_attempt=AAAAA}] 12/07/04 13:55:07 INFO job.SimpleStepHandler: Executing step: [firstJobStep] 12/07/04 13:55:07 ERROR job.AbstractJob: Encountered fatal error executing job org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:141) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) at org.test.SecondExample.main(SecondExample.java:59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) at java.lang.Thread.run(Thread.java:662) Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=secondJob at state=secondJob.firstJobStep with exception at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152) at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) ... 11 more Caused by: java.lang.NullPointerException at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:183) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) ... 13 more 12/07/04 13:55:07 INFO support.SimpleJobLauncher: Job: [FlowJob: [name=secondJob]] completed with the following parameters: [{programatic_attempt=AAAAA}] and the following status: [FAILED]
Java Code that dynamically load the bead-definition for spring-batch & spring-hadoop-
Any suggession what is going wrongCode:ApplicationContext context = new ClassPathXmlApplicationContext("context.xml"); Resource resource = context.getResource("context3.xml"); if(resource != null){System.out.println(" Resoruce is not null ");} GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx); int i_resource = reader.loadBeanDefinitions(resource);JobLauncher launcher = (JobLauncher) ctx.getBean("jobLauncher"); if( launcher != null ){ System.out.println("JobLauncher is not null"); }else{ System.out.println("JobLauncher is null"); return; } Job job = (Job) ctx.getBean("secondJob"); if( job != null ){ System.out.println("Job is not null"); }else{ System.out.println("Job is null"); return; } launcher.run(job, new JobParametersBuilder().addString("programatic_attempt", "AAAAA").toJobParameters());


Reply With Quote