How to configure using sessionListener spring boot 1.x

I am 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 another way to do this? You are welcome.

+5
source share
1 answer

What you mean is listeners for the Spring life cycle. This is not what you want.

Spring boot documentation state :

When using the built-in servlet container, you can register servlets, Filters, and all listeners from the Servlet specification (e.g. HttpSessionListener) directly as Spring beans. This can be especially convenient if you want to reference the 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(); } 
+9
source

Source: https://habr.com/ru/post/1214961/


All Articles