I would use CDI event inside EE app. Inside ejb module there is an EJB want to fire an event that will be consumed inside web module . The EJB wants to fire event is :
@Singleton
@Startup
public class DailyWork {
static final Logger logger =LoggerFactory.getLogger(DailyWork.class);
@PostConstruct
public void automaticTimeout() {
try {
CcPayload payload= new CcPayload(cc.getId()+"","SOME PAYLOAD");
new EventDispatcher().fire(payload);
}
catch (Exception ex) {
logger.warn("CAnnot calculate Balance for CC "+cc);
}
}
}
To fire the event I have this Dispatcher class (CDI bean on ejb module) :
import jakarta.enterprise.event.Event;
import jakarta.inject.Inject;
public class EventDispatcher {
@Inject
Event<CcPayload> event;
public void fire(Object payload) {
if (payload instanceof CcPayload){
event.fire((CcPayload)payload);
}
else
throw new UnsupportedOperationException();
}
}
And the beans.xml in <ejb module/META-INF folder is :
<?xml version="1.0" encoding="UTF-8"?>
<beans version="4.0" bean-discovery-mode="all"
xmlns=";
xmlns:xsi=";
xsi:schemaLocation=" .xsd">
</beans>
But the problem I am facing is the @Inject doesn't work and 'event' object is null when EJB use the disptacher to fire an event with payload.
Why Injection doesn't work ?