是否可以在没有Redis的情况下使用Spring Boot会话?

Fab*_*bio 15 spring spring-boot spring-session

查看Spring Boot文档,我只找到了使用Redis会话的示例,是否可以在没有 Redis的情况下使用它?

Adr*_*hum 12

正如另一个答案中所说:是的,您可以通过更改SessionRepository实现来更改会话持久性后端.

并且,Spring-Session提供了一个内置的替代方案MapSessionRepository,您可以在其中保存会话Map.

在Spring Session的示例中,有一个使用Hazelcast作为持久性后端的示例.它正在利用上面提到的Hazelcast创建MapSessionRepositoryMap实例.


小智 6

我知道我对这个问题有点迟了,但只是发帖以防其他人偶然发现这个问题.

从Spring Session 1.2.0开始,内置了一个JDBC会话存储库,可以像这样使用:

@Configuration
@EnableJdbcHttpSession // default session length and DB table name can be included on the annotation
public class SessionConfiguration {
    // code goes here if needed
}
Run Code Online (Sandbox Code Playgroud)

在Spring Session JAR中,org.springframework.session.jdbc包具有SQL脚本,可以为许多不同的DBMS(MySQL,Postgre等)创建表结构.

我开始在Spring Session 1.2.0里程碑版本中使用JDBC功能,我一路上都没有遇到任何问题.

  • 实际到Spring Boot:http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc-boot.html (2认同)