BERARM BERARM - 1 year ago 199
Java Question

How to configure sessionListener use spring boot 1.x

I'm new to Spring Boot.
Now ,I want to add a listener.


public MySessionListener implement HttpSessionListener

How to configure
Can I use
or other way to do it? Please.

Answer Source

What you are referring to are listeners for Spring context life-cycle. That is not what you want.

Spring boot documentation states:

When using an embedded servlet container you can register Servlets, Filters and all the listeners from the Servlet spec (e.g. HttpSessionListener) directly as Spring beans. This can be particularly convenient if you want to refer to a value from your during configuration.


import org.springframework.context.annotation.Bean;
import javax.servlet.http.HttpSessionListener;

public HttpSessionListener httpSessionListener(){
    // MySessionListener should implement javax.servlet.http.HttpSessionListener
    return new MySessionListener(); 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download