Search code examples
javamaveninjectjsr352jberet

JSR352: Annotation @Named doesn't work in Java SE


I'm building a demo of JSR352 (Batch Applications for the Java Platform) under Java SE, using the JBoss implementation JBeret. And I want to run the integration test for this job. In this batch job, there're 3 components:

  • io.mincong.batch.MyItemReader
  • io.mincong.batch.MyItemProcessor
  • io.mincong.batch.MyItemWriter

They're all named beans with annotation @Named, e.g.

@Named
public class MyItemProcessor implements ItemProcessor {
     // ...
}

Thanks to this annotation, I can use the job classes without typing the package name prefix io.mincong.batch in the my job file myJob.xml. And this works fine in Java EE container, like WildFly 10. However, in Java SE, it doesn't work anymore, I must add the package prefix. Here the job xml myJob.xml :

<?xml version="1.0" encoding="UTF-8"?>
<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd"
    version="1.0">
    <step id="printID">
        <chunk item-count="5">
            <!-- This works :
            <reader ref="io.mincong.batch.MyItemReader"/>
            <processor ref="io.mincong.batch.MyItemProcessor"/>
            <writer ref="io.mincong.batch.MyItemWriter"/> -->

            <!-- This doesn't work -->
            <reader ref="myItemReader"/>
            <processor ref="myItemProcessor"/>
            <writer ref="myItemWriter"/>
        </chunk>
    </step>
</job>

And you can find 2 mvn install log in annex, with and without package prefix. In other words, use and not-use @Named. Why this error happens ? Am I missing some dependencies ? Any idea ?

You can see my pom.xml below too. Additional informations :


Maven install failed when @Named is used

Mincongs-MBP:batch mincong$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building batch 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ batch ---
[INFO] Deleting /Users/mincong/Documents/workspace/batch/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ batch ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ batch ---
[INFO] Compiling 3 source files to /Users/mincong/Documents/workspace/batch/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ batch ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ batch ---
[INFO] Compiling 1 source file to /Users/mincong/Documents/workspace/batch/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ batch ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ batch ---
[INFO] Building jar: /Users/mincong/Documents/workspace/batch/target/batch.jar
[INFO] 
[INFO] --- maven-failsafe-plugin:2.17:integration-test (default) @ batch ---
[INFO] Failsafe report directory: /Users/mincong/Documents/workspace/batch/target/failsafe-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running io.mincong.batch.JobIT
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.3.4 (Final)
Jun 26, 2016 1:21:16 PM org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory create
INFO: WELD-ENV-000020: Using jandex for bean discovery
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.KafkaItemReader because of underlying class loading error: Type org.apache.kafka.clients.consumer.KafkaConsumer not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.KafkaItemWriter because of underlying class loading error: Type org.apache.kafka.clients.producer.KafkaProducer not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.HornetQItemReader because of underlying class loading error: Type org.hornetq.api.core.HornetQException not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.JasperReportsBatchlet because of underlying class loading error: Type net.sf.jasperreports.engine.data.JRAbstractTextDataSource not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:21:16 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.HornetQItemWriter because of underlying class loading error: Type org.hornetq.api.core.HornetQException not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:21:17 PM org.jboss.weld.environment.se.WeldContainer initialize
INFO: WELD-ENV-002003: Weld SE container STATIC_INSTANCE initialized
Jun 26, 2016 1:21:17 PM io.mincong.batch.JobIT setupJobEnv
INFO: setup env finished.
Jun 26, 2016 1:21:17 PM io.mincong.batch.JobIT shouldStart
INFO: executionId=1
Jun 26, 2016 1:21:17 PM org.jberet.runtime.runner.ChunkRunner run
ERROR: item-count=10, time-limit=0, skip-limit=-1, skipCount=0, retry-limit=-1, retryCount=0
Jun 26, 2016 1:21:17 PM org.jberet.runtime.runner.ChunkRunner run
ERROR: JBERET000007: Failed to run job myJob, printID, org.jberet.job.model.Chunk@4256e00a
java.lang.IllegalStateException: JBERET000600: Failed to create artifact with ref name myItemReader.  Ensure CDI beans.xml is present and batch.xml, if any, is configured properly.
    at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:185)
    at org.jberet.runtime.runner.AbstractRunner.createArtifact(AbstractRunner.java:156)
    at org.jberet.runtime.runner.ChunkRunner.run(ChunkRunner.java:134)
    at org.jberet.runtime.runner.StepExecutionRunner.runBatchletOrChunk(StepExecutionRunner.java:226)
    at org.jberet.runtime.runner.StepExecutionRunner.run(StepExecutionRunner.java:147)
    at org.jberet.runtime.runner.CompositeExecutionRunner.runStep(CompositeExecutionRunner.java:164)
    at org.jberet.runtime.runner.CompositeExecutionRunner.runFromHeadOrRestartPoint(CompositeExecutionRunner.java:88)
    at org.jberet.runtime.runner.JobExecutionRunner.run(JobExecutionRunner.java:60)
    at org.jberet.spi.JobExecutor$1.run(JobExecutor.java:99)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: JBERET000600: Failed to create artifact with ref name myItemReader.  Ensure CDI beans.xml is present and batch.xml, if any, is configured properly.
    at org.jberet.creation.ArtifactFactoryWrapper.getClassFromBatchXmlOrClassLoader(ArtifactFactoryWrapper.java:65)
    at org.jberet.creation.ArtifactFactoryWrapper.create(ArtifactFactoryWrapper.java:41)
    at org.jberet.runtime.context.JobContextImpl.createArtifact(JobContextImpl.java:183)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: myItemReader
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.jberet.creation.ArtifactFactoryWrapper.getClassFromBatchXmlOrClassLoader(ArtifactFactoryWrapper.java:63)
    ... 13 more

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.416 sec <<< FAILURE! - in io.mincong.batch.JobIT
shouldStart(io.mincong.batch.JobIT)  Time elapsed: 4.366 sec  <<< FAILURE!
java.lang.AssertionError: expected:<COMPLETED> but was:<FAILED>
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:145)
    at io.mincong.batch.JobIT.shouldStart(JobIT.java:47)

Weld SE container STATIC_INSTANCE shut down by shutdown hook

Results :

Failed tests: 
  JobIT.shouldStart:47 expected:<COMPLETED> but was:<FAILED>

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-failsafe-plugin:2.17:verify (default) @ batch ---
[INFO] Failsafe report directory: /Users/mincong/Documents/workspace/batch/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.863 s
[INFO] Finished at: 2016-06-26T13:21:20+02:00
[INFO] Final Memory: 31M/273M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.17:verify (default) on project batch: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/mincong/Documents/workspace/batch/target/failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Maven install success when @Named is not used

Mincongs-MBP:batch mincong$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building batch 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ batch ---
[INFO] Deleting /Users/mincong/Documents/workspace/batch/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ batch ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ batch ---
[INFO] Compiling 3 source files to /Users/mincong/Documents/workspace/batch/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ batch ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ batch ---
[INFO] Compiling 1 source file to /Users/mincong/Documents/workspace/batch/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ batch ---
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ batch ---
[INFO] Building jar: /Users/mincong/Documents/workspace/batch/target/batch.jar
[INFO] 
[INFO] --- maven-failsafe-plugin:2.17:integration-test (default) @ batch ---
[INFO] Failsafe report directory: /Users/mincong/Documents/workspace/batch/target/failsafe-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running io.mincong.batch.JobIT
Jun 26, 2016 1:25:25 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.3.4 (Final)
Jun 26, 2016 1:25:25 PM org.jboss.weld.environment.deployment.discovery.DiscoveryStrategyFactory create
INFO: WELD-ENV-000020: Using jandex for bean discovery
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.KafkaItemReader because of underlying class loading error: Type org.apache.kafka.clients.consumer.KafkaConsumer not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.KafkaItemWriter because of underlying class loading error: Type org.apache.kafka.clients.producer.KafkaProducer not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.HornetQItemReader because of underlying class loading error: Type org.hornetq.api.core.HornetQException not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.JasperReportsBatchlet because of underlying class loading error: Type net.sf.jasperreports.engine.data.JRAbstractTextDataSource not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:25:26 PM org.jboss.weld.bootstrap.MissingDependenciesRegistry handleResourceLoadingException
INFO: WELD-000119: Not generating any bean definitions from org.jberet.support.io.HornetQItemWriter because of underlying class loading error: Type org.hornetq.api.core.HornetQException not found.  If this is unexpected, enable DEBUG logging to see the full error.
Jun 26, 2016 1:25:26 PM org.jboss.weld.environment.se.WeldContainer initialize
INFO: WELD-ENV-002003: Weld SE container STATIC_INSTANCE initialized
Jun 26, 2016 1:25:26 PM io.mincong.batch.JobIT setupJobEnv
INFO: setup env finished.
Jun 26, 2016 1:25:26 PM io.mincong.batch.JobIT shouldStart
INFO: executionId=1
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 0
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 1
...
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 95
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 96
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 97
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 98
Jun 26, 2016 1:25:26 PM io.mincong.batch.MyItemWriter writeItems
INFO: 99
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.304 sec - in io.mincong.batch.JobIT
Weld SE container STATIC_INSTANCE shut down by shutdown hook

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-failsafe-plugin:2.17:verify (default) @ batch ---
[INFO] Failsafe report directory: /Users/mincong/Documents/workspace/batch/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ batch ---
[INFO] Installing /Users/mincong/Documents/workspace/batch/target/batch.jar to /Users/mincong/.m2/repository/io/github/mincongh/batch/0.0.1-SNAPSHOT/batch-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/mincong/Documents/workspace/batch/pom.xml to /Users/mincong/.m2/repository/io/github/mincongh/batch/0.0.1-SNAPSHOT/batch-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.810 s
[INFO] Finished at: 2016-06-26T13:25:28+02:00
[INFO] Final Memory: 32M/284M
[INFO] ------------------------------------------------------------------------

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>io.github.mincongh</groupId>
    <artifactId>batch</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>batch</name>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.testSource>1.7</maven.compiler.testSource>
        <maven.compiler.testTarget>1.7</maven.compiler.testTarget>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <arquillian.version>1.0.0.Alpha5</arquillian.version>
        <wildfly.version>10.0.0.Final</wildfly.version>
        <jberet.version>1.3.0.Beta2</jberet.version>
    </properties>

    <build>
        <finalName>batch</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <!-- enable execution to run an integration test -->
                <executions>
                  <execution>
                    <goals>
                      <goal>integration-test</goal>
                      <goal>verify</goal>
                    </goals>
                  </execution>
                </executions>
                <configuration>
                    <systemPropertyVariables>
                        <jberet.tmp.dir>${project.build.directory}${file.separator}tmp</jberet.tmp.dir>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <!-- Write test in JUnit 4.x -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.3.0.Final</version>
            <scope>provided</scope>
        </dependency>
        <!-- jberet dependencies -->
        <dependency>
            <groupId>org.jboss.spec.javax.batch</groupId>
            <artifactId>jboss-batch-api_1.0_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.marshalling</groupId>
            <artifactId>jboss-marshalling</artifactId>
            <version>1.4.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-core</artifactId>
            <version>2.3.4.Final</version>
        </dependency>
        <dependency>
            <groupId>org.wildfly.security</groupId>
            <artifactId>wildfly-security-manager</artifactId>
            <version>1.1.2.Final</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>19.0</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld.se</groupId>
            <artifactId>weld-se</artifactId>
            <version>2.3.4.Final</version>
        </dependency>
        <!-- contains all classes of JBeret batch runtime. This library is 
             required to run batch applications in both Java SE and Java EE 
             environment. -->
        <dependency>
            <groupId>org.jberet</groupId>
            <artifactId>jberet-core</artifactId>
            <version>${jberet.version}</version>
        </dependency>
        <!-- contains implementation classes of JBeret batch runtime 
             specifically for Java SE environment. -->
        <dependency>
            <groupId>org.jberet</groupId>
            <artifactId>jberet-se</artifactId>
            <version>${jberet.version}</version>
        </dependency>
        <!-- a zip file containing the following content, and provides a 
             good start to write and run batch applications with JBeret in 
             Java SE. 
             *  All libraries required to run batch applications in 
                Java SE environment
             *  default configuration file, jberet.properties for 
                configuring JBeret batch runtime in Java SE environment 
             *  jberet-support library and its common transitive 
                dependencies 
         -->
        <dependency>
            <groupId>org.jberet</groupId>
            <artifactId>jberet-distribution</artifactId>
            <version>${jberet.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.191</version>
        </dependency>
    </dependencies>

</project>

Solution

  • You should add the @Dependent annotation to you Reader, Processor and Writer.

    To ensure that Contexts and Dependency Injection (CDI) works in your batch artifacts, follow these steps.

    1. Define your batch artifact implementations as CDI named beans using the Named annotation.
    2. Provide a public, empty, no-argument constructor for your batch artifacts.
    3. Specify the CDI name for the batch artifacts in the job definition file, instead of using the fully qualified name of the class.
    4. Ensure that your module is a CDI bean archive by annotating your batch artifacts with the javax.enterprise.context.Dependent annotation or by including an empty beans.xml deployment description with your application.
    @Dependent
    @Named("MyItemReaderImpl")
    public class MyItemReaderImpl implements ItemReader { ... }
    
    <step id="stepA" next="stepB">
      <chunk>
        <reader ref="MyItemReaderImpl"></reader>
        ...
      </chunk>
    </step>
    

    More infos on: https://docs.oracle.com/javaee/7/tutorial/batch-processing005.htm