Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HttpSession在服务器重新启动后保持不变_Java_Spring_Spring Mvc_Spring Security_Httpsession - Fatal编程技术网

Java HttpSession在服务器重新启动后保持不变

Java HttpSession在服务器重新启动后保持不变,java,spring,spring-mvc,spring-security,httpsession,Java,Spring,Spring Mvc,Spring Security,Httpsession,我在学春天。执行登录/注销功能。 这就是我的控制器的外观: @RequestMapping(value="/successfulLoginAuth", method=RequestMethod.GET) public ModelAndView postHttpLogin(HttpSession session, Authentication authInfo) { ModelAndView mav = new ModelAndView(); mav.setViewName("redirect

我在学春天。执行登录/注销功能。 这就是我的控制器的外观:

@RequestMapping(value="/successfulLoginAuth", method=RequestMethod.GET)
public ModelAndView postHttpLogin(HttpSession session, Authentication authInfo) 
{

ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/index.html");
session.setAttribute("authInfo", authInfo);

return mav;

}
登录是通过SpringSecurity使用我已经实现的dao服务执行的。那很好

这是index.jsp的内容:

<% 
    HttpSession session1 = request.getSession(false);
    Authentication authInfo; 
    if( (session1 != null) && 
        ( (authInfo = (Authentication)session1.getAttribute("authInfo")) != null) 
      )
    {

        out.print(" yo " + authInfo.getName() + " " + authInfo.getAuthorities().iterator().next().getAuthority());
    }
    else
    {
%>    
<a href="${pageContext.request.contextPath}/registration">New? Sign Up!</a><br/>

<a href="${pageContext.request.contextPath}/login">Existing? Sign In!</a><br/>
<%} %>



当我登录并重新启动服务器时,我仍在登录。服务器重启后会话信息不应该丢失吗?如果我重新启动浏览器,它将正常工作(即会话信息丢失)

这是我的Spring安全配置:

<http auto-config="true"  use-expressions="true">
        <intercept-url pattern="/" access="permitAll" />
        <intercept-url pattern="/logout" access="permitAll" />
        <intercept-url pattern="/accessdenied" access="permitAll" />
        <form-login login-page="/login" default-target-url="/successfulLoginAuth" authentication-failure-url="/accessdenied" />
        <logout logout-success-url="/logout" />
    </http>

<authentication-manager>
    <authentication-provider user-service-ref="myUserDetailsService"></authentication-provider>
  </authentication-manager>

我假设您使用的是
Tomcat
,它使用管理器组件在应用程序生命周期之间持久化会话。您可以在中更改所有这些设置


我认为这也取决于你所做的改变。Eclipse的Tomcat服务器插件将决定它是否应该刷新序列化的HttpSession

从Docs SaveOnRestart属性

Should all sessions be persisted and reloaded when Tomcat is shut down and restarted (or when this application is reloaded)? By default, this attribute is set to true.
可以通过将context.xml中的属性更改为false来控制这一点

<Manager pathname="">
      <saveOnRestart>false</saveOnRestart>
</Manager> 

假的

谢谢!这是一个服务器配置的东西。在context.xml下,我看到了这一行,并做了更改:取消注释这一行以禁用Tomcat重启期间的会话持久性:
如果您想知道为什么Tomcat会这样做而从不进行设置,请在临时目录中的某个地方查找名为SESSIONS.ser的文件-Tomcat将此文件保存为正确关机过程的一部分。