【问题标题】:How to resolve the "Error creating bean with name 'step2' defined in class path resource " exception如何解决“创建类路径资源中定义的名称为'step2'的bean时出错”异常
【发布时间】: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


【解决方案1】:

你缺少 spring-retry Classifier 类的依赖 jar

Spring Retry 提供了一个关于重试失败操作的抽象

【讨论】:

    猜你喜欢
    • 2019-08-05
    • 1970-01-01
    • 2020-03-25
    • 2021-06-28
    • 2021-10-13
    • 2018-12-27
    • 2021-05-20
    • 2014-09-10
    • 1970-01-01
    相关资源
    最近更新 更多