-
1. Re: Unable to inject EJB into batchlet
pbenedict Oct 30, 2014 5:32 PM (in response to pbenedict)I solved it with the help of this link:
http://docs.oracle.com/javaee/7/tutorial/doc/batch-processing005.htm
FWIW, none of Oracle's examples inject into the Batchlet (my use case). They are all injecting into the ItemReader or ItemWriter instances. However, their solution works for batchlets as well.
1. Annotate your batchlet with @Named
2. Annotate your batchlet with @Dependent
3. Refer to your batchlet in the Job XML by the bean name (not the class name).
-
2. Re: Unable to inject EJB into batchlet
cfang Oct 30, 2014 10:07 PM (in response to pbenedict)Great you found the solution. Yes, CDI injection into batchlet, or any batch artifact, should work the same as injecting into ItemReader or ItemWriter. I guess it's just batchlet is used not as common as chunk ItemReader and ItemWriter, hence fewer examples.
jberet-support includes a built-in batchlet, JasperReportsBatchlet, that shows injections of various types:
jsr352/JasperReportsBatchlet.java at master · jberet/jsr352 · GitHub
-
3. Re: Unable to inject EJB into batchlet
cfang Oct 31, 2014 9:51 AM (in response to cfang)@EJB and @Resource are non-CDI, kinda legacy injection annotations, which only work on Java EE component classes (like EJB bean classes, servlet class, servlet filters, web listeners, EJB interceptors, etc). A batch artifact itself is not Java EE component so @EJB or @Resource will not work. Any @Inject should just work in batch artifacts if properly wired.