server.session-timeout 似乎只适用于嵌入式tomcat.
我放了一个日志语句来检查会话最大间隔时间.在手动将war文件部署到tomcat后,我意识到默认会话超时值(30分钟)仍在使用.
如何使用spring-boot设置会话超时值(不是针对嵌入式tomcat,而是针对独立应用程序服务器)?
jus*_*tin 21
以防有人发现这有用:
如果您使用的是Spring Security,则可以扩展SimpleUrlAuthenticationSuccessHandler类并在身份验证成功处理程序中设置会话超时:
public class NoRedirectSavedRequestAwareAuthenticationSuccessHandler
extends SimpleUrlAuthenticationSuccessHandler {
public final Integer SESSION_TIMEOUT_IN_SECONDS = 60 * 30;
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response,
Authentication authentication)
throws ServletException, IOException {
request.getSession().setMaxInactiveInterval(SESSION_TIMEOUT_IN_SECONDS);
// ...
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginProcessingUrl("/login")
.successHandler(new NoRedirectSavedRequestAwareAuthenticationSuccessHandler())
.failureHandler(new SimpleUrlAuthenticationFailureHandler())
.and().httpBasic();
}
}
Run Code Online (Sandbox Code Playgroud)
将Spring Boot应用程序部署到独立服务器时,配置会话超时的方式与在任何其他war部署中的方式相同.
对于Tomcat,您可以通过在maxInactiveIntervalmanager.xml中的manager元素上配置属性server.xml或使用session-timeoutweb.xml中的元素来设置会话超时.请注意,第一个选项将影响部署到Tomcat实例的每个应用程序.
| 归档时间: |
|
| 查看次数: |
39858 次 |
| 最近记录: |