ringadingding
ringadingding

Reputation: 475

JSR batch - constructor injection using @BatchProperty

I am currently working on a JSR batch job. I tried injecting incoming parameters in my batchlet constructor.

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

This throws a dependency exception.

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=)};

I am lost here, I will appreciate any help understanding this behavior.

Upvotes: 1

Views: 448

Answers (1)

cheng
cheng

Reputation: 1138

Batch spec supports field injection only. So your code should be changed to inject the batch property to a field. For example,

@Inject
@BatchProperty
private String prop1;

The batch property name defaults to the java class field name. Otherwise, you can specify the name with @BatchProperty(name = "property-name").

Upvotes: 1

Related Questions