In a batch project, I need to load some reference data from the database before processing. I am trying to do so by injecting a service bean in the JobListener and loading the data in the "beforeJob" method but the serviceBean is always null.
public interface ServiceBean extends Serializable { ... }
@Stateless
@Named
public class ServiceBeanImpl implements ServiceBean { ... }
@Named
//@Dependent <- Tried adding this
public class CollectJobListener extends AbstractJobListener {
@Inject JobContext jobContext;
@Inject
private ServiceBean serviceBean; // Always NULL
@Override
public void beforeJob() throws Exception {...}
}
I tried with multiple types of listeners (chunk, process, write listeners) but the result is always the same.
The injection works fine though if I do it in the "main" artifacts (reader, proccesor, writer).
@Named
@Dependent
public class MyItemWriter extends AbstractItemWriter {
@Inject
private ServiceBean serviceBean; // Works !
}
Any ideas on how I might get this to work ?
Or should I just do my setup job in one of the main artifacts ?
Thanks