您所指的是Spring上下文生命周期的侦听器。那不是你想要的。
Spring Boot文档指出:
使用嵌入式Servlet容器时,您可以直接将Servlet规范中的Servlet,过滤器和所有侦听器(例如HttpSessionListener)注册为Spring
Bean。如果要在配置过程中引用application.properties中的值,这可能特别方便。
更新:
import org.springframework.context.annotation.Bean;import javax.servlet.http.HttpSessionListener;@Beanpublic HttpSessionListener httpSessionListener(){ // MySessionListener should implement javax.servlet.http.HttpSessionListener return new MySessionListener(); }


