Job-wide artifact injection with CDI ProducerTweet
Posted on Tuesday Feb 25, 2014 at 05:37PM in Technology
- jBeret 1.0.1Beta-SNAPSHOT
- WildFly 8.0.0.Final
Why need it?
- Logger injection through CDI is easy and useful, but for jBatch programming of some occasions, I guess that Job-wide Logger is better than typical class-wide logger. thus, I will try it this time.
- With CDI, we can reduce some annoying code, even related to Job Properties so I also will try to inject a job-level property to a Batchlet through Producer.
- jBatch resources
- CDI resources
- Test class
How does it work?
- 2 Injections are declared in InjectBatchlet.
- Both of them will be produced by JobWideArtifactProducer.
- JobWideArtifactProducer creates:
- a logger. the name contains job name.
- a Date. it came from job-level property named “baseDate”.
18:14:51,064 INFO [job.jobwideproducer] (batch-batch - 3) process(): baseDate=14/02/25 0:00
- Injection of variables such as working directory of the job may be useful too.