Announcement Announcement Module
Collapse
No announcement yet.
Exception in using SimpleJobRepository from Spring-batch 2.1.7 release Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception in using SimpleJobRepository from Spring-batch 2.1.7 release

    I have applicationContext.xml as below :

    <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-2.5.xsd">

    <bean id="transactionManager"
    class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager" />


    <!-- Declare jobReposirory -->

    <bean id="jobRepository"
    class="org.springframework.batch.core.repository.s upport.SimpleJobRepository">

    <constructor-arg>

    <bean
    class="org.springframework.batch.core.repository.d ao.MapJobInstanceDao"></bean>

    </constructor-arg>


    <constructor-arg>

    <bean
    class="org.springframework.batch.core.repository.d ao.MapJobExecutionDao"></bean>

    </constructor-arg>

    <constructor-arg>

    <bean
    class="org.springframework.batch.core.repository.d ao.MapStepExecutionDao"></bean>

    </constructor-arg>

    <constructor-arg>

    <bean
    class="org.springframework.batch.core.repository.d ao.MapExecutionContextDao"></bean>



    </constructor-arg>



    </bean>


    <!-- Declare jobLauncher -->

    <bean id="jobLauncher"
    class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">

    <property name="jobRepository" ref="jobRepository" />

    </bean>

    </beans>


    I have a simplejob.xml file as below :

    <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-2.5.xsd">

    <import resource="applicationContext.xml" />

    <!-- Tasklet or Step definitions -->

    <bean id="hello" class="com.simple.spring.PrintTasklet">
    <property name="message" value="Hello" />
    </bean>

    <bean id="space" class="com.simple.spring.PrintTasklet">
    <property name="message" value=" " />
    </bean>

    <bean id="world" class="com.simple.spring.PrintTasklet">
    <property name="message" value="World !!!" />
    </bean>

    <!-- Common Generic Tasklet definition -->

    <bean id="taskletStep" abstract="true"
    class="org.springframework.batch.core.step.tasklet .TaskletStep">

    <property name="transactionManager" ref="transactionManager" />
    <property name="jobRepository" ref="jobRepository" />
    </bean>

    <!-- Job definition -->

    <bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJo b">

    <property name="name" value="simpleJob" />

    <property name="steps">

    <list>

    <bean parent="taskletStep">
    <property name="tasklet" ref="hello" />

    </bean>

    <bean parent="taskletStep">
    <property name="tasklet" ref="space" />
    </bean>

    <bean parent="taskletStep">
    <property name="tasklet" ref="world" />
    </bean>

    </list>

    </property>

    </bean>


    </beans>

    Java App class as :

    package com.simple.spring;

    import org.omg.CORBA.CTX_RESTRICT_SCOPE;
    import org.springframework.batch.core.Job;
    import org.springframework.batch.core.JobExecution;
    import org.springframework.batch.core.JobParameters;
    import org.springframework.batch.core.JobParametersInvali dException;
    import org.springframework.batch.core.launch.JobLauncher;
    import org.springframework.batch.core.repository.JobExecu tionAlreadyRunningException;
    import org.springframework.batch.core.repository.JobInsta nceAlreadyCompleteException;
    import org.springframework.batch.core.repository.JobResta rtException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;

    public class SimpleJobTest {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    String[] springConfig =
    {
    "simpleJob.xml"
    };

    ApplicationContext appCtxt = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobLauncher = (JobLauncher) appCtxt.getBean("jobLauncher");

    Job job = (Job) appCtxt.getBean("simpleJob");

    try {
    JobExecution jobExec = jobLauncher.run(job, new JobParameters());

    System.out.println("Execution Status : "+jobExec.getStatus());

    } catch (JobExecutionAlreadyRunningException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (JobRestartException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (JobInstanceAlreadyCompleteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (JobParametersInvalidException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    }

    On running the above SimpleJobTest.java, i get the below error :

    2013-12-14 03:06:52,534 INFO [org.springframework.context.support.ClassPathXmlAp plicationContext] - <Refreshing org.springframework.context.support.ClassPathXmlAp [email protected]: startup date [Sat Dec 14 03:06:52 IST 2013]; root of context hierarchy>
    2013-12-14 03:06:52,633 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from class path resource [simpleJob.xml]>
    2013-12-14 03:06:52,904 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from class path resource [applicationContext.xml]>
    2013-12-14 03:06:53,065 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL [email protected]: defining beans [transactionManager,jobRepository,jobLauncher,hello ,space,world,taskletStep,simpleJob]; root of factory hierarchy>
    2013-12-14 03:06:53,302 INFO [org.springframework.batch.core.launch.support.Simp leJobLauncher] - <No TaskExecutor has been set, defaulting to synchronous executor.>
    2013-12-14 03:06:53,411 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultL [email protected]: defining beans [transactionManager,jobRepository,jobLauncher,hello ,space,world,taskletStep,simpleJob]; root of factory hierarchy>
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'simpleJob' defined in class path resource [simpleJob.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: JobRepository must be set
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 93)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:290 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:192)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:93)
    at com.simple.spring.SimpleJobTest.main(SimpleJobTest .java:25)
    Caused by: java.lang.IllegalArgumentException: JobRepository must be set
    at org.springframework.util.Assert.notNull(Assert.jav a:112)
    at org.springframework.batch.core.job.AbstractJob.aft erPropertiesSet(AbstractJob.java:109)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1417)
    ... 12 more

    I am unable to figure out what needs to be set in JobRepository. Could anyone please help on this, as i am unable to execute a simple batch example.
    Reference link is http://java.dzone.com/news/spring-batch-hello-world-1

  • #2
    Sorry for not getting to this sooner. We are in the process of moving to StackOverflow for our forums.

    This question is probably a better candidate for StackOverflow, perhaps against the #spring-batch tag. If you do post it there, please reply here with the link. Thanks!

    Comment

    Working...
    X