Spring Batch Java Config事务 - 属性等价

时间:2014-05-28 19:08:30

标签: java spring spring-batch

在Spring批处理中,您可以像这样设置事务isolationpropagation

<job id="someJob" xmlns="http://www.springframework.org/schema/batch">
   <step id="readWriteDate">
      <tasklet transaction-manager="transactionManager">
         <transaction-attributes isolation="DEFAULT" propagation="REQUIRED" timeout="30"/>
         <chunk reader="dbItemReader" processor="dbItemProcessor" writer="dbItemWriter"
                commit-interval="2" />
      </tasklet>
   </step>
</job>

我找不到java配置等效。

2 个答案:

答案 0 :(得分:2)

好吧它就在那里

@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();
    }
}

对于默认实现,请查看http://docs.spring.io/spring/docs/4.0.5.RELEASE/javadoc-api/org/springframework/transaction/interceptor/package-summary.html

答案 1 :(得分:1)

就像迈克尔·普拉洛(Michael Pralow)所说的那样。仅添加一个具体示例,您可以通过实例化默认事务属性来设置隔离级别:

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

然后在步骤构建器中使用它。希望对您有帮助!