java - Spring Batch: adjusting transaction properties in a fault tolerant step -


i have quite basic step in spring batch job (using java config):

@bean public step step1() {     return stepbuilders.get("stepname")         .<object1, void>chunk(50)         .reader(reader(inputresource(null))         .processor(processor())         .listener(steplogger())         .transactionattribute(transactiontimeoutattribute(null))         .build(); }     .......  @bean @stepscope public stepexecutionlistener steplogger() {     return new steplogger(); }  @bean @stepscope public transactionattribute transactiontimeoutattribute(         @value("#{jobparameters[transactiontimeout]}") integer timeout) {     timeout = timeout != null ? timeout : default_transaction_timeout;     rulebasedtransactionattribute transactionattribute = new rulebasedtransactionattribute();     transactionattribute.settimeout(timeout);     return transactiontimeout; } 

as can see, it's requirement transaction timeout can given job parameter. works flawlessly, , if set transactiontimeout job parameter low, job execution fail transactions time out before chunk completes.

however, if try tack on fault tolerance (to able skip amount of failed elements), falls apart. when add faulttolerant() step config able specify skip policy etc, this:

@bean public step step1() {     return stepbuilders.get("stepname")         .<object1, void>chunk(50)         .reader(reader(inputresource(null))         .processor(processor())         .faulttolerant()         .listener(steplogger())         .transactionattribute(transactiontimeoutattribute(null))         .build(); } 

spring can no longer start context (on jetty now), , throws following exception on startup:

beancreationexception: error creating bean name 'scopedtarget.transactiontimeoutattribute': scope 'step' not active current thread; consider defining scoped proxy bean if intend refer singleton; nested exception java.lang.illegalstateexception: no context holder available step scope 

what correct way of specifying both transaction attribute , skip policy of step in spring batch using java config?

edit: make question bit more understandable, requirement make fault tolerant step transaction timeout configurable job parameter. non-fault tolerant step, that's not problem, make step scoped transactionattribute bean job parameters wired in. faulttolerantstepbuilder handles transaction attribute differently (it merges given transaction attribute internal one), step scope not available. how can use job parameters configure transaction attribute of fault tolerant step (java config)?

if using spring batch 3 or newer can mark transaction attribute , step @jobscope. prevent fault tolerant step access transaction attribute early.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -