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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With