Results 1 to 2 of 2

Thread: error while invoking programatically instead of by CommandLineJobRunner

  1. #1
    Join Date
    Dec 2011
    Posts
    25

    Default error while invoking programatically instead of by CommandLineJobRunner

    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 -
    Code:
    mvn exec:java -Dexec.mainClass="org.test.SecondExample"
    Error I got -
    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-
    Code:
        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());
    Any suggession what is going wrong
    Last edited by paragflume; Jul 4th, 2012 at 05:57 AM.

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Your programmatic code is a mess. You load an application context only to load another resource and then you load an empty application context and then you use the bean definition reader manually....
    There are numerous examples in our test suite, the docs or google on how to setup an application context.
    Just start with GenericXmlApplicationContext (use the constructor that accepts a string/resource) and you're good to go.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •