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

时间:2015-10-27 23:48:20

标签: spring spring-boot spring-session

查看Spring Boot文档我只找到了使用Redis会话的示例,是否可以使用而不使用 Redis?

3 个答案:

答案 0 :(得分:12)

如另一个答案中所述:是的,您可以通过更改select实施来更改会话持久性后端。

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

在Spring Session的示例中,有一个sample using Hazelcast作为持久性后端。它正在利用上述Map与Hazelcast创建的MapSessionRepository实例。

答案 1 :(得分:6)

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

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

<html>
<head>
    <title>Authors</title>
    <script>
        function addauthor()
        {
            console.log('function is working');
            var no;
            but = document.getElementById("addauth");
            no = Number(but.value)+1;
            document.getElementById('next').innerHTML='<p><div>'+no+'</div>   \
            <p>Whom do you want to add ? </p>    \
            <label><input type="radio" name="add" value="student" onchange="showForm()">Student</label>     \
            <label><input type="radio" name="add" value="teacher" onchange="showForm()">Teacher</label>     \
            <div id=""></div>          \
            </p>      \
            <p id="next">   \
                <button id="addauth" onclick="addauthor()" value="'+no+'">Add</button>   \
            </p>';
        }
    </script>
</head>
<body>
    <p><div>1</div>
    <p>Whom do you want to add ? </p>
    <label><input type="radio" name="add" value="student" onchange="showForm()">Student</label>
    <label><input type="radio" name="add" value="teacher" onchange="showForm()">Teacher</label>
    <div></div>
    </p>
    <p id="next">
        <button id="addauth" onclick="addauthor()" value="1">Add</button>
    </p>
</body>
</html>

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

我在Spring Session 1.2.0里程碑版本中开始使用JDBC功能,在此过程中我没有遇到任何问题。

答案 2 :(得分:0)

您可以使用任何想要存储会话的技术。 Spring Session提供了必须实现的接口SessionRepository来存储和检索会话。因此,只需使用您的存储技术创建该接口的实现,并将该实现配置为Spring bean。

相关问题