Package com. Joe. Sessionlistener;
The import org. Springframework. Boot. SpringApplication;
The import org. Springframework. Boot. Autoconfigure. SpringBootApplication;
The import org. Springframework. Boot. Web. Servlet. ServletComponentScan;
@ ServletComponentScan
@ SpringBootApplication
Public class SessionlistenerApplication {
Public static void main (String [] args) {
SpringApplication. Run (SessionlistenerApplication. Class, args);
}
}
Custom listener classes:
Package com. Joe. Sessionlistener. The listener;
The import lombok. Extern. Slf4j. Slf4j;
The import javax.mail. Servlet. The annotation. WebListener;
The import javax.mail. Servlet. HTTP. HttpSessionEvent;
The import javax.mail. Servlet. HTTP. HttpSessionListener;
@ Slf4j
@ WebListener
Public class MyHttpSessionListener implements HttpSessionListener {
Public MyHttpSessionListener () {
The info (" MyHttpSessionListener constructor... ");
}
@ Override
Public void sessionCreated (HttpSessionEvent se) {
HttpSessionListener. Super. SessionCreated (se);
The info (" session created... {}, "se. GetSession () getId ());
}
@ Override
Public void sessionDestroyed (HttpSessionEvent se) {
HttpSessionListener. Super. SessionDestroyed (se);
The info (" session destroyed... {}, "se. GetSession () getId ());
}
}
Test method: visit the web site of the static page: index. An interface in HTML or controller, found no into the session created here!
In addition: complete source code of the project in: https://gitee.com/zhouciming/sessionlistener
Which master stretched out a helping hand, very grateful!