Skip to content

Instantly share code, notes, and snippets.

@joshkitt
Last active July 15, 2019 16:25
Show Gist options
  • Save joshkitt/a53aed64e97f51932e9cf163b90a3767 to your computer and use it in GitHub Desktop.
Save joshkitt/a53aed64e97f51932e9cf163b90a3767 to your computer and use it in GitHub Desktop.
Java Session Listener
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@Configuration
public class SessionConfiguration {
@Bean
public HttpSessionListener httpSessionListener() {
return new HttpSessionListener() {
@Override
public void sessionCreated(HttpSessionEvent se) {
System.out.println("Session Created with Session id: " + se.getSession().getId());
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("Session Destroyed for Session id: " + se.getSession().getId());
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment