【问题标题】:Spring Batch 4.0 and Spring Boot 1.5.9Spring Batch 4.0 和 Spring Boot 1.5.9
【发布时间】:2018-06-13 06:14:50
【问题描述】:

快速了解 Spring Batch 和 Spring Boot 只想使用注释。让演示应用程序https://spring.io/guides/gs/batch-processing/ 工作,它使用 hsqldb 并且一切正常。之后我选择切换到oracle。我想像以前的工作一样使用存储库数据库表。当我切换到 oracle 11g 时,spring 批处理表中的插入器会抱怨 SERILIZABLE。所以昨天花了很大一部分时间追查这个问题,我知道我可能需要在 jobrepository 上设置一个隔离级别。问题是没有站点进入这个,并且显示 xml/java 的文档也没有清楚地解释。我查看了 Spring Batch github 中的示例,也找不到任何内容。是否有示例说明如何创建和作业存储库并为此更改隔离级别?此时燃烧时间,没有前进的动力。

尝试使用以下代码设置隔离并获取:BatchConfigurationException: java.lang.IllegalArgumentException: Invalid transaction attribute token: [READ_COMMITTED]

public class BatchConfiguration extends DefaultBatchConfigurer {
    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    private PlatformTransactionManager transactionManager;


    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Autowired
    private DataSource dataSource;

    @Override
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTransactionManager(transactionManager);
          factory.setIsolationLevelForCreate("READ_COMMITTED");
        //     factory.setTablePrefix("BATCH_");
        factory.setMaxVarCharLength(1000);
        return factory.getObject();
    }

    @Bean
    public JdbcCursorItemReader<BusnPrtnr> itemReader() {
        return new JdbcCursorItemReaderBuilder<BusnPrtnr>()
                .dataSource(dataSource)
...

【问题讨论】:

  • 请尽量坚持事实。你的问题读起来就像一个故事。
  • 据我所知,spring batch 4.0要求你使用Spring boot 2.0。它不适用于 Spring boot 1.x。您仍然可以使用 Spring batch 3.x 和 Spring boot 1.5.x 使用注解。尝试更改您的 Spring Batch 版本。

标签: spring-boot spring-batch


【解决方案1】:

这里的Java代码示例有错误:https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#txConfigForJobRepository

应该是factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ"); 而不是factory.setIsolationLevelForCreate("REPEATABLE_READ");

XML 代码示例正确(XML 解析器addsISOLATION_ 前缀在幕后)。

这里有一个拉取请求来解决这个问题:https://github.com/spring-projects/spring-batch/pull/577/files#diff-de2cb44d4395c5ad35d1fc05bbace8f1R620

该修复将成为 4.0.1 版本的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-10
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2017-09-27
    相关资源
    最近更新 更多