Announcement Announcement Module
Collapse
No announcement yet.
Session bean destroy order Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session bean destroy order

    Hello Spring community,

    I am developing a web application with Spring 3.2.1 and JSF2. Now I have a question on session beans and the @PreDestroy callback...

    Assuming I have two session beans where one session bean gets the other session bean injected.
    Is there a defined order in that way that the session bean which is referenced by an other session bean gets
    destroyed after the other one - in the following scenario: Is the AuthManager instance always destroyed
    after the ExecutorBean instance when the session is invalidated so that I can access fields from the referenced bean within the pre-destroy method?

    Code:
    @Controller("authManager")
    @Scope("session")
    public class AuthManager {
      private int userId;
      public int getUserId() {
        return userId;
      }
      public void login() {
        userId = 10;
      }
      public void logout() {
        // Invalidate session
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
      }
    }
    
    @Controller("executorBean")
    @Scope("session")
    public class ExecutorBean {
      // Reference to the other session bean
      @Resource(name="authManager")
      private AuthManager authManager;
    
      @PreDestroy
      public void preDestroy() {
        // Is it guaranteed that the authManager bean is always destroyed after the executor bean?
        System.out.println(authManager.getUserId());
      }
    }
    Thanks in advance, best regards,
    michael
Working...
X