Announcement Announcement Module
Collapse
No announcement yet.
JobRepository is mandatory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JobRepository is mandatory

    I am trying to write a simple spring job. Its failing with the below error. Any help is really appreciated.

    Caused by: java.lang.IllegalArgumentException: JobRepository is mandatory
    at org.springframework.util.Assert.notNull(Assert.jav a:112)
    at org.springframework.batch.core.step.AbstractStep.a fterPropertiesSet(AbstractStep.java:71)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.afterPropertiesSet(TaskletStep.java:123)
    at org.springframework.batch.core.step.item.SimpleSte pFactoryBean.getObject(SimpleStepFactoryBean.java: 338)
    at org.springframework.batch.core.configuration.xml.S tepParserStepFactoryBean.getObject(StepParserStepF actoryBean.java:215)
    at org.springframework.beans.factory.support.FactoryB eanRegistrySupport$1.run(FactoryBeanRegistrySuppor t.java:121)


    applicationContext.xml:
    <bean id="jobRepository-transactionManager" class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager" />

    <bean id="jobRepository" class="org.springframework.batch.core.repository.s upport.MapJobRepositoryFactoryBean">
    <property name="transactionManager" ref="jobRepository-transactionManager" />
    </bean>

    <bean id="jobLauncher" class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher" >
    <property name="jobRepository" ref="jobRepository" />
    </bean>

    <batch:job id="jobProcessor" job-repository="jobRepository">
    <batch:step id="step1">
    <batch:tasklet transaction-manager="jobRepository-transactionManager">
    <batch:chunk reader="modelReader" writer="modelWriter"
    commit-interval="1000" />
    </batch:tasklet>
    </batch:step>
    </batch:job>

  • #2
    Spring batch version

    Same code works in Spring batch version 2.0.0, but not in 2.1.0

    Am I missing anything that needs in version 2.1.0.

    Please help.
    Last edited by varmawku; Jan 19th, 2012, 11:55 AM.

    Comment


    • #3
      please use CODE tags and post the complete configuration with code to run the batch

      Comment


      • #4
        Here is the full code

        Adding the code:

        Configuration file:
        Code:
        <beans xmlns="http://www.springframework.org/schema/beans"
        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch"
        	xsi:schemaLocation="http://www.springframework.org/schema/beans
        						http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        						http://www.springframework.org/schema/batch
        						http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
        	
        	<bean class="org.springframework.batch.core.scope.StepScope" />
        	
        	<bean id="modelWriter" class="ModelContextWriter" />
        	<bean id="modelReader" class="org.springframework.batch.item.file.FlatFileItemReader">
        		<property name="resource" value="classpath:sampleFile.txt" />
        		<property name="linesToSkip" value="1" />
        		<property name="lineMapper">
        			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
        				<property name="lineTokenizer">
        					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
        						<property name="delimiter" value="," />
        					</bean>
        				</property>
        				<property name="fieldSetMapper">
        					<bean class="ModelContextMapper" />
        				</property>
        			</bean>
        		</property>
        	</bean>
        	
        	<bean id="jobRepository-transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /> 
        	
        	<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
        		<property name="transactionManager" ref="jobRepository-transactionManager" />
        	</bean>
         
        	<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher" >
        		<property name="jobRepository" ref="jobRepository" />
        	</bean> 
         
        	<batch:job id="jobProcessor" job-repository="jobRepository">
        		<batch:step id="step1">
        			<batch:tasklet transaction-manager="jobRepository-transactionManager">
        				<batch:chunk reader="modelReader" writer="modelWriter"
        					commit-interval="1000" />
        			</batch:tasklet>
        		</batch:step>
        	</batch:job>
        
        </beans>
        Main method to run:
        Code:
        ClassPathResource resource = new ClassPathResource("applicationContext.xml");
        BeanFactory factory = new XmlBeanFactory(resource);
        
        Job job = (Job) factory.getBean("jobProcessor");
        SimpleJobLauncher launcher = (SimpleJobLauncher) factory.getBean("jobLauncher");
        
        launcher.run(job, new JobParameters());

        Comment


        • #5
          the run method seems to be the problem, with your code it won't run for me also

          this works for me:

          Code:
          // create context
          ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
          
          // get the job
          Job job = (Job) context.getBean("jobProcessor");
          
          // get the jobLauncher
          JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");
          
          // launch the job
          JobExecution jobExecution = launcher.run(job, new JobParameters());
          
          // (optional)assert job run status
          // assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

          Comment


          • #6
            thanks a ton Michael.
            It works when I change it to use ClassPathXmlApplicationContext.

            Any idea why BeanFactory doesn't work.

            Comment


            • #7
              nope, but from looking into the code (and spring doc too) it seems the beanFactory is not supposed to be used and/or we are missing some steps to complete the actual creating of the context (resolve dependencies, beanPostProcessors, etc.)

              Comment


              • #8
                Originally posted by michael.lange View Post
                nope, but from looking into the code (and spring doc too) it seems the beanFactory is not supposed to be used and/or we are missing some steps to complete the actual creating of the context (resolve dependencies, beanPostProcessors, etc.)
                Might be.
                You solved the issue on which I am freaking out for last couple of days. Thanks for the help

                Comment

                Working...
                X