JBatch: BatchProperty injection on Wildfly 9

483 views Asked by At

I just started learning JSR-352 and made it through a view tutorials. But i have a problem with the injection of batch-properties: The important part of my "myJob.xml" is this

<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<properties>
    <property name="name" value="MyName"/>
</properties>

With the following code it is no problem to get the property in a Batchlet or Chunk:

@Inject
JobContext batchContext;

@Override
public String process() throws Exception {
    Thread.sleep(100);
    String name = batchContext.getProperties().getProperty("name");

But in different tutorials I also find a simpler way to do this with

@Inject
@BatchProperty(name="name")
String name;

But the value of name is always null. So the injection is not working. Is this a failure of mine or is this a problem with wildfly 9.0.1 on which i deployed the Batch Application?

1

There are 1 answers

0
Veilchen4ever On BEST ANSWER

I'm answering my own question - hopefully this helps other beginners with JBatch.

I didn't noticed that I only can inject properties (with @Inject @BatchProperty) that are declared inside a "batchlet"-tag or inside a "chunk"-tag. With properties on job-level or step-level this doesn't work.