日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Boot——Spring Session Redis整合Spring Security时错误【RedisConnectionFactory is required】解决方案

發布時間:2024/10/5 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Boot——Spring Session Redis整合Spring Security时错误【RedisConnectionFactory is required】解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題描述

異常棧棧底

Caused by: java.lang.IllegalStateException: RedisConnectionFactory is requiredat org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.2.11.RELEASE.jar:5.2.11.RELEASE]at org.springframework.data.redis.core.RedisAccessor.afterPropertiesSet(RedisAccessor.java:38) ~[spring-data-redis-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.data.redis.core.RedisTemplate.afterPropertiesSet(RedisTemplate.java:127) ~[spring-data-redis-2.3.5.RELEASE.jar:2.3.5.RELEASE]at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.createRedisTemplate(RedisHttpSessionConfiguration.java:291) ~[spring-session-data-redis-2.3.1.RELEASE.jar:2.3.1.RELEASE]at org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.sessionRepository(RedisHttpSessionConfiguration.java:120) ~[spring-session-data-redis-2.3.1.RELEASE.jar:2.3.1.RELEASE]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.11.RELEASE.jar:5.2.11.RELEASE]... 121 common frames omitted

官方文檔

https://docs.spring.io/spring-session/docs/current/reference/html5/index.html#spring-security-concurrent-sessions?

問題分析

關鍵異常信息?

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.session.data.redis.RedisIndexedSessionRepository]: Circular reference involving containing bean 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration' - consider declaring the factory method as static for independence from its containing instance. Factory method 'sessionRepository' threw exception; nested exception is java.lang.IllegalStateException: RedisConnectionFactory is requiredat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.11.RELEASE.jar:5.2.11.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.11.RELEASE.jar:5.2.11.RELEASE]... 120 common frames omitted

關鍵的關鍵

Circular reference involving containing bean

HttpSessionListener的Bean和Spring Session Redis自動配置出來的Bean在同一個配置類中,導致循環引用。

例如:

/*** @author ShenTuZhiGang* @version 1.0.0* @date 2021-02-25 10:45*/ @Configuration @EnableRedisHttpSession public class CustomRedisHttpSessionConfig {@Autowiredprivate FindByIndexNameSessionRepository sessionRepository;/*** SpringSessionBackedSessionRegistry是session為Spring Security提供的* 用于在集群環境下控制會話并發的會話注冊表實現類*/@Beanpublic SpringSessionBackedSessionRegistry sessionRegistry() {return new SpringSessionBackedSessionRegistry(sessionRepository);}/*** httpSession的會話監聽,*/@Beanpublic HttpSessionEventPublisher httpSessionEventPublisher() {return new HttpSessionEventPublisher();} }

解決方案

拆分

/*** @author ShenTuZhiGang* @version 1.0.0* @date 2021-02-25 10:45*/ @Configuration @EnableRedisHttpSession public class CustomRedisHttpSessionConfig {/*** httpSession的會話監聽,*/@Beanpublic HttpSessionEventPublisher httpSessionEventPublisher() {return new HttpSessionEventPublisher();} }

其他的放在?Spring Security 配置類中

參考文章

How to isolate spring boot app redis and spring boot session global redis

Spring Security集成Spring Session并存儲session到Redis中,報錯: Circular reference involving containing bean

總結

以上是生活随笔為你收集整理的Spring Boot——Spring Session Redis整合Spring Security时错误【RedisConnectionFactory is required】解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。