0
I am creating a class using deltaspike and Quartz, using @scheduled. In this class I inject a CDI bean, which is a service class. I chose to use deltaspike because it controls the CDI context within the classes that use Uartz. The bean, however, is not injected and is null. No exception is fired on the console. The execute code does not appear to be called. But by taking all the code out of the method, removing @Inject and leaving only the log calls, it works perfectly. What may be missing to set up for dependency injection to work? Follow code.
@Scheduled(cronExpression = "0 0/1 * * * ?")
public class NotificacaoAgendaJob implements Job {
Logger logger = Logger.getLogger("br.com.nutrierp.scheduler");
@Inject
AgendaService agendaService;
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
logger.info("Iniciando Job...");
List<Agenda> agendas = agendaService.todasAgendasDoSistema();
for (Agenda agenda : agendas) {
LocalDateTime dataAgendada = agenda.getDataInicial();
LocalDateTime dataAtual = LocalDateTime.now();
Duration intervalo = Duration.between(dataAtual, dataAgendada);
if (intervalo.toHours() <= 24 && intervalo.toHours() > 0) {
agendaService.enviarEmailDeNotificacao(agenda);
}
}
logger.info("Finalizando Job...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Where is the rest of the code, the code of web.xml, springContext.xml?
– Weslley Barbosa
Weslley, in the deltaspike documentation there is no reference to additional configurations in web.xml, nor required configurations in Quartz.proprties. in fact, without including @Inject and removing the code that uses the injected object, the execute method runs. My application does not use spring, CDI only
– Alexandre Camilo
And if the Agendaservice class ? Vc added @Named ?
– Weslley Barbosa
Normally for a dependency to be created, you add @named, I think the Notificaoagendajob class is not a bean so it does not load the Agendaservice
– Weslley Barbosa