I am beginner in Spring framework.
In my case Session can be expire by following way
--> Success Log-out (Explicit Log-out )
--> Session Timeout (Implici
I have solved my problem by following way similar @Codo answer
@Component
public class SessionCreatedListenerService implements ApplicationListener {
private static final Logger logger = LoggerFactory
.getLogger(SessionCreatedListenerService.class);
@Autowired
HttpSession httpSession;
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
if(applicationEvent instanceof HttpSessionCreatedEvent){ //If event is a session created event
}else if(applicationEvent instanceof HttpSessionDestroyedEvent){ //If event is a session destroy event
// handler.expireCart();
logger.debug(""+(Long)httpSession.getAttribute("userId"));
logger.debug(" Session is destory :" ); //log data
}else if(applicationEvent instanceof AuthenticationSuccessEvent){ //If event is a session destroy event
logger.debug(" athentication is success :" ); //log data
}else{
/*logger.debug(" unknown event occur : " Source: " + ); //log data
}
}
}