首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >春季批量5中的DefaultBatchConfiguration扩展不工作

春季批量5中的DefaultBatchConfiguration扩展不工作
EN

Stack Overflow用户
提问于 2022-10-21 13:43:35
回答 2查看 97关注 0票数 1

为了实现Spring 5的自定义批处理配置,遵循关于博客:春季批5里程碑6JavaDoc春季批5里程碑8的正式文档,我编写了以下代码,通过Spring 3 RC1使用Spring 5:

代码语言:javascript
运行
复制
    @Configuration
    class MyBatchConfiguration extends DefaultBatchConfiguration {        
        @Override
        protected DataFieldMaxValueIncrementerFactory getIncrementerFactory() {
            return new MyDataFieldMaxValueIncrementerFactory();
        }
    }

但是我只得到一个关于我的MyBatchConfiguration#jobRepository Bean的错误,非法地覆盖JobRepositoryFactoryBean#jobRepository Bean。这很奇怪,因为JobRepositoryFactoryBean没有jobRepository

有人知道怎么解决这个问题吗?

错误:

org.springframework.beans.factory.BeanDefinitionStoreException::在上下文初始化过程中遇到的异常--取消刷新尝试:在类路径资源my/package/MyBatchConfigur.class:@Bean定义中非法重写的org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;定义: Generic : class org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;scope=;abstract=false;lazyInit=null;autowireMode=0;dependencyCheck=0;autowireCandidate=true;primary=false;factoryBeanName=null;factoryMethodName=null;initMethodNames=null destroyMethodNames=null;

编辑:我在https://github.com/JD-CSTx/SpringBatchBugJobRepo下构建了一个演示项目。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-25 06:16:38

在您的示例中,您同时使用了EnableBatchProcessingDefaultBatchConfiguration,这是不正确的。在文档 of v5中,您需要使用EnableBatchProcessingDefaultBatchConfiguration,但不能同时使用:

代码语言:javascript
运行
复制
@EnableBatchProcessing should not be used with DefaultBatchConfiguration.
You should either use the declarative way of configuring Spring Batch
through @EnableBatchProcessing, or use the programmatic way of extending
DefaultBatchConfiguration, but not both ways at the same time.

Spring也有一个关于这个这里的笔记。

票数 1
EN

Stack Overflow用户

发布于 2022-10-24 16:20:22

我可以通过以下方式解决这个问题/你的回购问题:

  • 移动@EnableBatchProcessing从:@配置公共类ImportJobConfiguration {//.
  • @Configuration @EnableBatchProcessing公共类SpringBatchDemo扩展DefaultBatchConfiguration {// .

原因是BatchAutoConfiguration的细节。

DefaultBatchConfiguration 应将(当前/始终)注释为

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74154573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档