为了实现Spring 5的自定义批处理配置,遵循关于博客:春季批5里程碑6和JavaDoc春季批5里程碑8的正式文档,我编写了以下代码,通过Spring 3 RC1使用Spring 5:
@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下构建了一个演示项目。
发布于 2022-10-25 06:16:38
在您的示例中,您同时使用了EnableBatchProcessing
和DefaultBatchConfiguration
,这是不正确的。在文档 of v5中,您需要使用EnableBatchProcessing
或DefaultBatchConfiguration
,但不能同时使用:
@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也有一个关于这个这里的笔记。
发布于 2022-10-24 16:20:22
我可以通过以下方式解决这个问题/你的回购问题:
@EnableBatchProcessing
从:@配置公共类ImportJobConfiguration {//.原因是BatchAutoConfiguration
的细节。
DefaultBatchConfiguration
应将(当前/始终)注释为
https://stackoverflow.com/questions/74154573
复制相似问题