0 Replies Latest reply on Nov 29, 2007 4:51 PM by beligum

    @PreDestroy and injected JavaBeans

    beligum

      Hi all,

      I'm trying to do the following:

      @Stateful
      @Scope(SESSION)
      @Name("outboxManager")
      public class OutboxManagerImpl extends AbstractManagerImpl implements OutboxManager, Serializable
      {
       private Map<Principal, List<EmailMessage>> queuedMessages;
      
       @In(create=true)
       private EmailMessenger emailMessenger;
      
       [constructors, getters, setters, ...]
      
       @PreDestroy
       public void cleanup()
       {
       try {
       sendAllQueuedMessages();
       } catch (EmailException e) {
       e.printStackTrace();
       }
       }
       @Remove
       @Destroy
       public void destroy()
       {
       }
      }
      


      Everything works fine, but when the @PreDestroy method is called, the injected JavaBean (POJO with @Name("emailMessenger")) has become null. I tried to re-inject it manually, but some other initialization-things (eg. the email renderer) go wrong then.

      Am I missing the point here that the injected values are already irrevocably destroyed when @PreDestroy is reached/called, or is this expected behavior? If so, how do I send my queued mails when the session goes out of scope?

      thanks a lot,

      b.