Spring batch -Run JobLauncher -
i integrated spring batch in project , have problem in running joblauncher.
in class joblauncher have :
public class xxxjoblauncher { @autowired @qualifier("testjob") job testjob; @autowired joblauncher joblauncher; @serviceactivator public void run(filemetadata filemetadata) { /// jobparametersbuilder jobparametersbuilder = new jobparametersbuilder(); jobparametersbuilder.addstring("uuiid", filemetadata.getuuid()); jobparametersbuilder.addlong("id", dataimport.getid()); try { joblauncher.run(testjob, jobparametersbuilder.tojobparameters()); } catch (jobexecutionalreadyrunningexception | jobrestartexception | jobparametersinvalidexception | jobinstancealreadycompleteexception e) { e.printstacktrace(); } }
for configuration use xml config :
configbatch.xml:
<import resource="classpath:job-config.xml"/> <bean id="jobrepositoryfactory" class="org.springframework.batch.core.explore.support.jobexplorerfactorybean"> <property name="datasource" ref="datasource"/> <property name="tableprefix" value="batch_"/> </bean> <bean id="jobrepository" class="org.springframework.batch.core.repository.support.simplejobrepository" factory-bean="jobrepositoryfactory"/> <bean id="batchtaskexecutor" class="org.springframework.scheduling.concurrent.threadpooltaskexecutor" destroy-method="shutdown"> <property name="corepoolsize" value="6"/> <property name="allowcorethreadtimeout" value="true"/> <property name="waitfortaskstocompleteonshutdown" value="true"/> </bean> <bean id="joblauncher" class="org.springframework.batch.core.launch.support.simplejoblauncher"> <property name="jobrepository" ref="jobrepository"/> <property name="taskexecutor" ref="batchtaskexecutor"/> </bean>
in job-config.xml have :
<batch:job id="testjob" incrementer="incrementer" job-repository="jobrepository"> <batch:step id="step1"> <batch:tasklet throttle-limit="4" transaction-manager="transactionmanager" task-executor="batchtaskexecutor"> <batch:chunk reader="xxxreader" processor="passthroughitemprocessor" writer="xxxwriter" skip-limit="100" commit-interval="10"> <batch:skippable-exception-classes> <batch:include class="org.springframework.batch.item.file.flatfileparseexception"/> </batch:skippable-exception-classes> <batch:listeners> <batch:listener ref="xxxlistener"/> </batch:listeners> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <bean id="xxxreader" class="com.reader.xxxreader" scope="step"> <constructor-arg value="#{jobparameters[uuiid]}" name="uuiid"/> </bean> <bean id="xxxwriter" class="com.writer.xxxwriter" scope="step"> <constructor-arg value="#{jobparameters[ id]}" name="id"/> </bean> <bean id="xxxlistener" class="com.listener.xxxlistener"> </bean> <bean id="passthroughitemprocessor" class="org.springframework.batch.item.support.passthroughitemprocessor"/> <bean id="incrementer" class="org.springframework.batch.core.launch.support.runidincrementer"/>
when debug in class joblauncher stop in jobluancher.run , have no exception it's seems spring batch doesn't recognizes reader , whriter !!is there suggestion?
i resolved problem in batchconfig.xml :
<batch:job-repository id="jobrepository" data-source="datasource" transaction-manager="batchtransactionmanager"/> <bean class="org.springframework.batch.core.configuration.support.jobregistrybeanpostprocessor"> <property name="jobregistry" ref="jobregistry"/> </bean> <bean id="jobregistry" class="org.springframework.batch.core.configuration.support.mapjobregistry"/> <bean id="joblauncher" class="org.springframework.batch.core.launch.support.simplejoblauncher"> <property name="jobrepository" ref="jobrepository"/> </bean> <bean id="batchtransactionmanager" class="org.springframework.batch.support.transaction.resourcelesstransactionmanager"/> <bean id="batchtaskexecutor" class="org.springframework.scheduling.concurrent.threadpooltaskexecutor" destroy-method="shutdown"> <property name="corepoolsize" value="4"/> <property name="allowcorethreadtimeout" value="true"/> <property name="waitfortaskstocompleteonshutdown" value="true"/> </bean> <bean id="jobexplorer" class="org.springframework.batch.core.explore.support.jobexplorerfactorybean"> <property name="datasource" ref="datasource"/> </bean>
Comments
Post a Comment