title: How to get notified when session is about to expire? Spring-boot
body: <p>I've tried using</p>
  
  <pre><code>public void onApplicationEvent(ApplicationEvent event)
  {
  
  
    if(event instanceof SessionDestroyedEvent){
  </code></pre>
  
  <p>and</p>
  
  <pre><code> @WebListener
   public class SessionListener implements HttpSessionListener {
  
        @Override                                                                                                                                                                                                   
       public void sessionDestroyed(HttpSessionEvent se) {
  </code></pre>
  
  <p>First one, I didn't get <code>SessionDestoryedEvent</code> event at all.</p>
  
  <p>It seems spring might notify us after session is expired.<br>
  Is there a reliable way to get notified <em><code>before</code></em> session is expired?  </p>
  
  <p>Preferably I want solution without <code>spring-session</code> package. </p>
  
  <p>I'm not getting <code>sessionDestroyed</code> nor <code>sessionCreated</code> with the following code..</p>
  
  <pre><code> import javax.servlet.http.HttpSessionEvent;
   import javax.servlet.http.HttpSessionListener;
   import javax.servlet.annotation.WebListener;
   import org.springframework.stereotype.Component;
  
   @WebListener
   public class MySessionListener implements HttpSessionListener {
  
     private static int totalActiveSessions;
  
     public static int getTotalActiveSession(){
       return totalActiveSessions;
     }
  
     public MySessionListener()
     {
       System.out.println("MySessionListener -------------");
  
     }
     @Override                                                                                                                                                                         
   public void sessionCreated(HttpSessionEvent arg0) {
     totalActiveSessions++;                                                                                                                                                            
   System.out.println("sessionCreated - add one session into counter");                                                                                                              
  
  }
  
  @Override                                                                                                                                                                         
   public void sessionDestroyed(HttpSessionEvent arg0) {
     totalActiveSessions--;
     System.out.println("sessionDestroyed - deduct one session from counter");
     }
   }
  </code></pre>