[cdi-dev] @Destroyed(ApplicationScoped.class)

Mark Struberg struberg at yahoo.de
Tue Apr 28 14:56:28 EDT 2015


Hi!

The CDI-1.2 spec says in 6.7.3:

„An event with qualifier @Initialized(ApplicationScoped.class) is fired when the application context is initialized and an event with qualifier @Destroyed(ApplicationScoped.class) is fired when the application is destroyed. "

Now from the pure wording („IS initialized“, „IS destroyed“) I’d say that both events must be fired _after_ the state is reached. Means _after_ the context got initialized and _after_ the context got destroyed.

Means an observer like

@ApplicationScoped
public class MyBean {
  public void endIt(@Observes @Destroyed(ApplicationScoped.class) endObject) {
    doSomething()
  }
}

will _never_ get invoked. 
Because the bean (and the whole context) will be already killed…

You can observe this event in a @Singleton scoped bean, but not in an @ApplicationScoped bean.
If you like to do _that_, then simply use a @PreDestroy.

Do others share this interpretation? Do we need to clarify anything?

LieGrue,
strub


More information about the cdi-dev mailing list