【发布时间】:2019-02-02 15:44:14
【问题描述】:
我的示例 spring 批处理项目的 step2() 方法在一台 PC 中运行良好,并在另一台 PC 中引发以下错误。
谁能解释一下我的代码有什么问题?
Error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step2' defined in class path resource [com/xxxx/yyy/configuration/CustomJobConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.Step]: Factory method 'step2' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/classify/Classifier
方法:
@Bean
public Step step2() {
System.out.println("Entering step2()");
return stepBuilderFactory.get("step2")
.<String, String>chunk(Integer.valueOf(chunkSize))
.faultTolerant()
.reader(reader())
.writer(writer())
.build();
}
【问题讨论】:
-
检查你的类路径中是否有 org.springframework.classify.Classifier.jar
-
你使用maven或gradle之类的依赖管理工具吗?如果是这样,那么您需要在您的项目中导入
spring-batch-infrastructure,这将带来spring-retry依赖并解决您的问题。否则,您需要确保您的类路径中有spring-retry。 -
感谢您的回复。我的课程路径中确实有 spring-batch-infrastructure jar。奇怪的是它在一台机器上工作,它在另一台机器上抛出上述异常。
标签: java spring spring-batch noclassdeffounderror spring-retry