Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure sessionListener use spring boot 1.x

I'm new to Spring Boot. Now ,I want to add a listener.
e.g public MySessionListener implement HttpSessionListener
How to configure SpringApplication? Can I use SpringApplication.addListener() or other way to do it? Please.

like image 859
BERARM Avatar asked Mar 09 '15 09:03

BERARM


1 Answers

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 application.properties during configuration.

UPDATE:

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

@Bean
public HttpSessionListener httpSessionListener(){
    // MySessionListener should implement javax.servlet.http.HttpSessionListener
    return new MySessionListener(); 
}
like image 135
luboskrnac Avatar answered Sep 19 '22 12:09

luboskrnac