Como @Injetar em um PhaseListener
Eu adicionei umPhaseListener
parafaces-config.xml
:
<lifecycle>
<phase-listener>com.project.NotificationListener</phase-listener>
</lifecycle>
A classe parece estar correta, pois é bem simples.
public class NotificationListener implements PhaseListener {
@Inject
private MyCDIStuff stuff;
@Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
@Override
public void beforePhase(PhaseEvent event) {
this.stuff.doStuff();
}
}
O método 'beforePhase' é chamado corretamente, no entanto, o objeto MyCDIStuff é nulo. Eu tentei usar anotação@Singleton
para a classe que provavelmente estava incorreta, e também não fez a injeção funcionar.
Existe uma maneira de injetar beans gerenciados CDI noPhaseListener
?