Spring Batch Java Config transaction-attributes equivalent

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:10:33

well it is there

@Configuration
public class StepWithTx {

    @Autowired
    private StepBuilderFactory steps;

    @Bean
    public Step step() throws Exception {
        return steps
                .get("CustomTxStep")
                .<String, String>chunk(10)
                .transactionAttribute(transactionAttribute...)
                .reader(reader...)
                .processor(processor...)
                .writer(writer...)
                .build();
    }
}

for default implementations take a look at http://docs.spring.io/spring/docs/4.0.5.RELEASE/javadoc-api/org/springframework/transaction/interceptor/package-summary.html

It's like Michael Pralow say. Just to add a concrete example you can set the isolation level by instantiating a default transaction attribute :

  
DefaultTransactionAttribute transactionWithIsolationReadCommited = new DefaultTransactionAttribute();
transactionWithIsolationReadCommited.setIsolationLevel(TransactionAttribute.ISOLATION_READ_COMMITTED);

And then use it in the step builder. Hope it helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!