BER*_*ARM 6 java spring servlets spring-mvc spring-boot
我是Spring Boot的新手.现在,我想添加一个监听器.
例如public MySessionListener implement HttpSessionListener
如何配置SpringApplication?我可以用SpringApplication.addListener()其他方式吗?请.
lub*_*nac 10
你所指的是Spring上下文生命周期的监听器.那不是你想要的.
使用嵌入式servlet容器时,您可以将Servlet规范中的Servlet,过滤器和所有侦听器(例如HttpSessionListener)直接注册为Spring bean.如果要在配置期间引用application.properties中的值,这可能特别方便.
更新:
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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7115 次 |
| 最近记录: |