java - Start a spring batch job when already within a transaction -


i have simple spring-service (among other tasks) starts spring batch job following code:

@autowired private jobregistry jobregistry;  @autowired private joblauncher joblauncher;  public void startmyjob() {     job job = jobregistry.getjob("myjobname");     jobparameters jobparameters = new jobparametersbuilder().tojobparameters();     joblauncher.run(job, jobparameters); } 

this works fine, long there no transaction active when serivce-method called. however, active transaction, exception:

caused by: java.lang.illegalstateexception: existing transaction detected in jobrepository. please fix , try again (e.g. remove @transactional annotations client). 

i cannot remove existing transaction, since implied due framework code not within reach.

so, how can start job anyway within context? new job should not use existing transaction. start own transaction - how configure make work?

use abstractjobrepositoryfactorybean.validatetransactionstate, use (warning: dragons ahead).

to use transaction can inject custom simplejoblauncher.executor method executor.run marked @transactional() (or create custom joblauncher , same trick on method run).

i haven't tried because haven't faced problem, hope can help.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -