Announcement Announcement Module
Collapse
No announcement yet.
Restarting a Job using JobOperator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Restarting a Job using JobOperator

    Hi,

    I am facing issue in restarting a Job using JobOperator. I am getting following exception.

    Code:
    ERROR [main] JobExecuter - No job configuration with the name [job11] was registered
    org.springframework.batch.core.launch.NoSuchJobException: No job configuration with the name [job11] was registered
    	at org.springframework.batch.core.configuration.support.MapJobRegistry.getJob(MapJobRegistry.java:79)
    	at org.springframework.batch.core.launch.support.SimpleJobOperator.restart(SimpleJobOperator.java:249)
    	at com.fbfs.cp.pic.batch.framework.JobExecuter.main(JobExecuter.java:38)

    Following is the configuration detail...

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    
    <beans default-lazy-init="true"
    	xmlns="http://www.springframework.org/schema/beans"
    	xmlns:batch="http://www.springframework.org/schema/batch"
    	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.0.xsd 
    						http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd">
    
    	<import resource="datasource-spring-config.xml" />
    	<import resource="hibernate-spring-config.xml" />
    	<import resource="jobs-spring-config.xml" />
    	<import resource="dao-spring-config.xml" />
    	<import resource="service-spring-config.xml" />
    	<import resource="factories-spring-config.xml" />
    
    	<bean id="daoInterceptor"
    		class="com.fbfs.cp.pic.framework.dao.CoreDaoIntercepter" />
    
    	<bean id="exceptionManager"
    		class="com.fbfs.cp.pic.framework.exception.ExceptionManager">
    		<property name="handler">
    			<value>logging</value>
    		</property>
    	</bean>
    
    	<batch:job-repository id="jobRepository" table-prefix="JBF_BATCH_"
    		data-source="loggingDataSource" />
    		
    
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    
    	<bean id="jobExplorer"
    		class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    		<property name="dataSource" ref="loggingDataSource" />
    		<property name="tablePrefix" value="JBF_BATCH_" />
    	</bean>
    
    	<bean id="jobRegistry"
    		class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
    
    	<bean id="jobOperator"
    		class="org.springframework.batch.core.launch.support.SimpleJobOperator">
    		<property name="jobExplorer" ref="jobExplorer" />
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="jobRegistry" ref="jobRegistry" />
    		<property name="jobLauncher" ref="jobLauncher" />
    	</bean>
    
    	<bean
    		class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
    		<property name="jobRegistry" ref="jobRegistry" />
    	</bean>
    
    </beans>
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    
    <beans default-lazy-init="true"
    	xmlns="http://www.springframework.org/schema/beans"
    	xmlns:batch="http://www.springframework.org/schema/batch"
    	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.0.xsd 
    						http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd">
    
    
    	
    	<batch:job id="job11" restartable="true">
    		<batch:step id="job1-step1">
    			<batch:tasklet reader="job1Step1ItemReader"
    				writer="job1Step1ItemWriter" commit-interval="0" />
    		</batch:step>
    
    	</batch:job>
    
    
    	<bean id="job1Step1ItemReader"
    		class="com.fbfs.cp.pic.batch.framework.reader.HibernateReader">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    		<property name="service">
    			<ref bean="sqlReaderService" />
    		</property>
    	</bean>
    
    
    	<bean id="job1Step1ItemWriter"
    		class="org.springframework.batch.item.database.HibernateItemWriter">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
    
    
    
    </beans>

    Using following code to restart the job...

    Code:
    				JobOperator jobOperator = (JobOperator) CommonApplicationContext.getContext().getBean("jobOperator");
    				jobOperator.restart(JobInitializer.instance().getJobExecutionId());
    Please help...

  • #2
    You should be getting an error because your commit-interval cannot be 0.

    Comment


    • #3
      Thanx for replying.

      I changed the commit-interval value to 1, but still it was giving me the same error.

      I am not really sure, but is it something related to JobReopsitory.

      Comment


      • #4
        After the first run of the job, do you see an entry in the database for "job11"?

        Comment


        • #5
          It looks like the registry isn't seeing your job for some reason. It looks like you've done everything correctly to me. I would wire in the job registry and see what it has in there. Are you using the CommandLineJobRunner to bootstrap your XML files?

          Comment


          • #6
            Yes, after the first run(i.e. running the job in START mode), I could see entry in database for 'job11'.

            No, I am not using CommandLineJobRunner to bootstrap my XML files.

            Comment

            Working...
            X