1
votes

I have a problem with a CDI Event fired from an EJB Timer.

Point is, that the save event can be fired via manual user action (e.g. fired from a CDI SessionScoped bean method). In this case, all registered observers should catch it. But if the the CDI Event fired from the Timer is caught by a SessionScoped bean (which is anyway not required), an exception is thrown that no active Context could be found.

So... how can I tell the CDI eventing mechanism that only ApplicationScoped beans should catch the event, in case it was fired by the EJB Timer ?

2

2 Answers

3
votes

I found the solution.

@Observes contains the parameter "notifyObserver". If you set this to Reception.IF_EXISTS, CDI won't create a SessionScoped bean outside an HTTP Request if there is none.

So the EJB Timer fired event won't be catched by a SessionScoped bean (because it does not exist) and the manually triggered one will be catched as there is an existing instance of the SessionScoped bean.

0
votes

Use qualifiers as described in this stackoverflow post: Select certain CDI event observer

(not sure it realy is a duplicate, but I think it is)