I am in dilemma to store session in redis using Spring and there are many methods and concepts to handle this issue. Some methods are listed below:
Spring Data Redis
Spring Session
Spring Session Manager
Now the question is what is the best combination to store (delete and so on) session in redis using spring.
I will be appreciated if someone help me with a simple explanation.
You're a little confused:
Spring Data Redis provides easy configuration and access to Redis from any type of Spring applications. It realize both low-level and high-level abstractions for interacting with the Redis store. In few words - just realization of Redis client library.
Spring Session provides an API and implementations for managing a user’s session information.
Spring Session Management is just a HTTP session related functonality focused to concurrency control, filtering and authentication strategy and do not work with Redis as is. it works with interfaces only.
Using Spring framework you are using Spring Session. You need only configure it to use Redis as backend as in official documentation sample and sample project with Redis session in spring application.
If you are using spring boot, then the changes you need for your application is pretty simple.
Add the following dependencies and add redis connection configuration in application.properties and you are good to go.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
I have a details post about this at https://springhow.com/spring-boot-security/session-redis/
Related
There's a straight-forward way of using redis, jdbc, etc as persistence for spring sessions with minimal configuration but due to some serialization issue which I have been facing in that approach, I am thinking of having a custom implementation to intercept the session and then write implementations for save and retrieval of the session in redis and spring security take care of everything else.
Currently, in my application (thymeleaf based frontend), I have integrated spring-security for a form-based authentication.
Just to mention, the issue I am facing and which is what I am trying to avoid, is that with the config based persistence approach, I am getting serialisation exceptions for the model classes which I am using in various views. I am not understanding why session layer is trying to persist other POJOs along with just the session. Tye solution was to have those POJOs implement Serializable but this was also required to be done for library classes as well.
I have been looking all over the internet on how to configure Spring MVC 3 with redis but all in vain. I want to connect to redis using Spring MVC 3.
I have worked with spring boot and spring-data-redis and everything is working fine. I can connect to redis and store sessions. But the project I am currently working on is legacy based. It uses spring 3 but I believe spring-data-redis is compatible with spring 4 and above. Are there any alternates to make connection between spring 3 and redis. Any tutorial would be helpful.
I expect to store session data like username in the redis using Spring MVC 3
Well, from the documentation of the oldiest available spring-data-redis release
it looks like the minimal 2.x version is indeed spring 4
However, Spring data redis 1.x should work with spring 3.x:
https://docs.spring.io/spring-data/redis/docs/1.4.0.M1/reference/htmlsingle/#why-spring-redis
Having said that I haven't tried it by myself and if you're only storing sessions in redis, maybe using spring data is an overkill.
After all you can create a Jedis plugin by yourself, expose it as a bean and call the commands directly via the jedis driver. Its also possible to go with reactive client...
I have spring boot 2.0.2.RELEASE application. Which uses Spring Data JPA Repositories to fetch Data from underlying db.
All I want to configure is that when I use any repository function to fetch data from database it used use stateless session to communicate with DB and fetching data.
I have googled tons of article and other resources but not found any way how to configure and do this.
Kindly guide me to any documentation or any blog or tell me how to configure to achieve the above requirements.
I have a spring-jpa-mvc-rest-hibernate web application that I use Java Config almost 99% on the whole app.
How can I configure Session per Request on pure Java Config? Preferable not using hibernate specific code, if that is possible.
I'm using Spring 4.2.2.RELEASE, Spring Data 1.11.0.RELEASE, Spring JPA 1.9.0.RELEASE, Spring WebMVC 4.2.2.RELEASE and Hibernate 5.0.2.Final.
Thanks a lot.
I have a Spring based application that uses Spring core, Spring MVC and Spring Data (Mongo) on the server side, and designed as a typical 3-tier application.
I have a list of services, that are typical Spring services/beans that I wish you integrate with memcached to cache some of my service results.
Can someone guide me to the steps to integrate memcached with spring for such an application?
A sample/tutorial/blog that gives a step by step process would be just great.
Thanks.
If you use Spring 3.1 take a look at Spring Cache abstraction. It's the easiest way to integrate caching in Spring application. Unfortunately Spring doesn't support memcached out of the box, there's only support for ehcache.
As far as I know there isn't available any provider that can store data to memcached through Spring Cache. In few days next version 3.0.0 of Simple Spring Memcached is going to be released with such support. In mean time you may try one of the latest snapshot or use Simple Spring Memcached 2.0.0 directly without Spring Cache abstraction.
UPDATE: Simple Spring Memcached 3.0.0 with Spring Cache integration is already available.
It's very trivial to do. You can look at 3levelmemcache project as an example at github its Spring based abstraction.