Is it possible to use Spring Boot session without Redis?
Asked Answered
U

4

18

Looking at the Spring Boot docs I only found examples to use session with Redis, Is it possible to use it without Redis?

Unbend answered 27/10, 2015 at 23:48 Comment(4)
i dont understand the question, are u saying spring-boot default session management is using redis?Puissance
No, he's talking about Spring Session, a separate framework for session clustering etc.Grot
How can I use the default session management with spring-boot? I don`t find anything in docs.Unbend
Or are you looking for "How to use HTTP Session provided by whatever container?". I cannot think of other "default" session management other than HTTP session.Greenes
G
14

As said in another answer: Yes, you can change the Session persistence backend by changing the SessionRepository implementation.

And, there is an built-in alternatives provided by Spring-Session, which is MapSessionRepository for which you can save session in a Map.

In the samples of Spring Session, there is a sample using Hazelcast as persistence backend. It is utilizing the above-mentioned MapSessionRepository with the Map instance created by Hazelcast.

Greenes answered 28/10, 2015 at 6:36 Comment(0)
O
6

I know I'm a bit late to this question, but just posting in case others stumble upon this question.

As of Spring Session 1.2.0, there is a JDBC session repository built in that can be used like this:

@Configuration
@EnableJdbcHttpSession // default session length and DB table name can be included on the annotation
public class SessionConfiguration {
    // code goes here if needed
}

In the Spring Session JAR, the org.springframework.session.jdbc package has SQL scripts to create the table structure for many different DBMSs (MySQL, Postgre, etc.)

I started using the JDBC functionality in a Spring Session 1.2.0 milestone release, and I had no issues along the way.

Oringa answered 26/5, 2016 at 19:26 Comment(1)
Actual to Spring Boot: docs.spring.io/spring-session/docs/current/reference/html5/…Trustee
G
0

You can use whatever technology you want to store the sessions. Spring Session provides the interface SessionRepository which you have to implement to store and retrieve the sessions. So just create an implementation of that interface with your storage technology and configure that implementation as Spring bean.

Grot answered 28/10, 2015 at 5:51 Comment(0)
C
0

The Idea of storing spring session in Redis, JDBC etc is to eliminate the http session stored in container(Ex. Tomcat). When http session is stored in container, it becomes cumbersome to share the session between containers in a cluster/cloud environment. Load Balancing can NOT be effective. Any f/w that supports distributed, in-memory, cache, etc can be considered for storing the spring session.

Go for jdbc if your deployment architecture is many container one database otherwise redis should be fine.

Oracle Caching Framework Reference https://docs.oracle.com/cd/A97335_02/caching.102/a88706/ic_intro.htm

Cell answered 23/3, 2023 at 5:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.