I'm using a Deltaspike (1.4.0) with Quartz (2.2.1) to schedule a job. In the TestJob bean is injected ResourceBundle. The producer of ResourceBundle needs a facesContext, but this always is null.
How can inject properly ResourceBundle in the scheduler bean and why facesContext is always null when is used @Scheduled?
@Scheduled(cronExpression = "0 0/1 * * * ?")
public class TestJob implements Job {
@Inject private EntityManager em;
@Inject private transient ResourceBundle i18n;
public TestJob() {}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("TestJob executed...");
}
}
ResourceBundle producer
public class ResourceBundleProducer implements Serializable {
@Inject public FacesContext facesContext;
@Produces
public ResourceBundle getResourceBundle() {
if (facesContext.getViewRoot() != null)
return ResourceBundle.getBundle("i18n.i18n", facesContext.getViewRoot().getLocale());
else
return ResourceBundle.getBundle("i18n.i18n", facesContext.getApplication().getViewHandler().calculateLocale(facesContext));
}
}
FacesContext producer
public class FacesContextProducer implements Serializable {
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
}