【发布时间】:2020-03-10 10:57:39
【问题描述】:
我已经在 Spring MVC 应用程序中实现了 Spring session。它在我的数据库中创建会话表并存储会话 ID。但我无法更改“MaxInactiveIntervalInSeconds”值。在基于 XML 的配置中,我更改了“MaxInactiveIntervalInSeconds”值,如下所示。
<bean class="org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds">
<value>60</value>
</property>
</bean>
它工作正常。但我无法在基于 java 的配置中更改“MaxInactiveIntervalInSeconds”值。我尝试了以下方法。
@Bean
public JdbcHttpSessionConfiguration setMaxInactiveIntervalInSeconds(JdbcHttpSessionConfiguration jdbcHttpSessionConfiguration) {
jdbcHttpSessionConfiguration.setMaxInactiveIntervalInSeconds(60);
return jdbcHttpSessionConfiguration;
}
但它不起作用。
我的 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;
}
}
和
public class SessionInitializer extends AbstractHttpSessionApplicationInitializer {
}
有什么办法可以做到吗?
【问题讨论】:
标签: java spring spring-mvc spring-session