Looking at the Spring Boot docs I only found examples to use session with Redis, Is it possible to use it without Redis?
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.
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.
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.
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
© 2022 - 2025 — McMap. All rights reserved.