Search code examples
javacdijsr352jberet

Java BatchProperty possible as List<String>?


Is it possible in JSR-352 / Java Batch to have batch properties as List? How would they get initialized from the batch job XML?

public class MyItemProcessor extends ItemProcessor {
    @Inject
    @BatchProperty
    private List<String> items;

    public final Object processItem(Object o) throws Exception {
        ...
    }
}

Here is a skeleton batch job xml:

<?xml version="1.0" encoding="UTF-8"?>
<job  xmlns="https://jakarta.ee/xml/ns/jakartaee" version="2.0" id="exportToExcel" restartable="true">
    <chunk item-count="10">
        ...some reader...
        <processor ref="MyItemProcessor">
            <properties>
                <property name="items"/> <-- how would the list of strings go in here?
            </properties>
        </processor>
        ...some writer...
    </chunk>
</job>

Solution

  • Yes. see JBeret examples below. This is specific to JBeret, not a standard feature in Java Batch spec.

    https://github.com/jberet/jsr352/blob/main/test-apps/propertyInjection/src/main/java/org/jberet/testapps/propertyinjection/PropertyInjectionBatchlet.java#L215

    https://github.com/jberet/jsr352/blob/main/test-apps/propertyInjection/src/main/resources/META-INF/batch-jobs/propertyInjection.xml#L38

    See JBeret Docs for more info. The list value can be simple comma-separated string values.