首页 > 解决方案 > JSR 批处理 - 使用 @BatchProperty 进行构造函数注入

问题描述

我目前正在从事 JSR 批处理作业。我尝试在我的批处理构造函数中注入传入参数。

@Inject
public MyBatchLet(@BatchProperty(name="prop1") String prop1){
    this.myProperty = prop1;
}

这会引发依赖异常。

Unsatisfied dependency expressed through constructor argument with index 0 of type [java.lang.String]: : No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.batch.api.BatchProperty(name=)};

我在这里迷路了,我将不胜感激理解这种行为的任何帮助。

标签: javaspring-batchbatch-processingjsr352

解决方案


批处理规范仅支持字段注入。因此,您的代码应更改为将批处理属性注入字段。例如,

@Inject
@BatchProperty
private String prop1;

批处理属性名称默认为 java 类字段名称。否则,您可以使用 指定名称@BatchProperty(name = "property-name")


推荐阅读