Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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的spring会话配置中更改MaxInactiveIntervalinsSeconds值?_Java_Spring_Spring Mvc_Spring Session - Fatal编程技术网

如何在基于java的spring会话配置中更改MaxInactiveIntervalinsSeconds值?

如何在基于java的spring会话配置中更改MaxInactiveIntervalinsSeconds值?,java,spring,spring-mvc,spring-session,Java,Spring,Spring Mvc,Spring Session,我已经在SpringMVC应用程序中实现了spring会话。它在我的数据库中创建会话表并存储会话ID。但我无法更改“MaxInactiveIntervalInSeconds”值。在基于XML的配置中,我更改了“MaxInactiveIntervalInSeconds”值,如下所示 <bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration">

我已经在SpringMVC应用程序中实现了spring会话。它在我的数据库中创建会话表并存储会话ID。但我无法更改“MaxInactiveIntervalInSeconds”值。在基于XML的配置中,我更改了“MaxInactiveIntervalInSeconds”值,如下所示

<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration"> 
        <property name="maxInactiveIntervalInSeconds"> 
            <value>60</value> 
        </property> 
     </bean>
但它不起作用

我的SessionConfig和SessionInitializer类如下所示

@Configuration
@EnableJdbcHttpSession
public class SessionConfig {
    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public JdbcHttpSessionConfiguration setMaxInactiveIntervalInSeconds(JdbcHttpSessionConfiguration jdbcHttpSessionConfiguration) {
        jdbcHttpSessionConfiguration.setMaxInactiveIntervalInSeconds(60);
        return jdbcHttpSessionConfiguration;
    }
}


有什么办法可以做到这一点吗?

我找到了一个办法。只需添加
httpServletRequest.getSession().setMaxInactiveInterval(intervalInSeconds)

这对我有用

编辑1 找到了另一种方法。这才是正确的做法

@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = intervalInSeconds)
public class SessionInitializer extends AbstractHttpSessionApplicationInitializer {

}
    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public String login(HttpServletRequest request, HttpServletResponse servletresponse){
       //Your logic to validate the login
       request.getSession().setMaxInactiveInterval(intervalInSeconds);
    }
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = intervalInSeconds)