Spring boot 无法在服务中使用RedisIndexedSessionRepository

Spring boot 无法在服务中使用RedisIndexedSessionRepository,spring-boot,spring-security,spring-session,Spring Boot,Spring Security,Spring Session,对于我的spring引导应用程序(2.3.3.RELEASE,Java 11),我使用spring会话,以下是对此的标准依赖项: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>

对于我的spring引导应用程序(2.3.3.RELEASE,Java 11),我使用spring会话,以下是对此的标准依赖项:

    <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>
我决定重新使用它。不幸的是,当我在我的服务中尝试这样做时,比如:

@Service
@RequiredArgsConstructor
public class SessionService {
    private final RedisIndexedSessionRepository sessionRepository;
应用程序启动时出现以下错误:

UPD。我发现,如果我将RedisIndexedSessionRepository添加到我的服务中,Spring不知何故不会执行负责在RedisHttpSessionConfiguration中设置redisConnectionFactory的代码(自动连线方法setRedisConnectionFactory,第204行)。但如果我从服务中删除RediIndexedSessionRepository,则会触发上述方法。我还尝试创建自己的bean RedisConnectionFactory,但它无法解决这个问题

啊,我在顶部的RedisHttpSessionConfiguration中找到了这条评论:

 * Exposes the {@link SessionRepositoryFilter} as a bean named
 * {@code springSessionRepositoryFilter}. In order to use this a single
 * {@link RedisConnectionFactory} must be exposed as a Bean.
但是仍然不明白如何在服务中使用RedisIndexedSessionRepository


是否有人可以建议如何处理此问题以及如何在应用程序中使用此存储库?

似乎RediIndexedSessionRepository不能简单地自动连接,我们必须手动执行此操作,如:

private final RedisIndexedSessionRepository sessionRepository;

public SessionService(RedisTemplate<Object, Object> redisTemplate) {
    this.sessionRepository = new RedisIndexedSessionRepository(redisTemplate);
}
private final redisedSessionRepository sessionRepository;
公共会话服务(RedisTemplate RedisTemplate){
this.sessionRepository=新的RedisIndexedSessionRepository(redisTemplate);
}
 * Exposes the {@link SessionRepositoryFilter} as a bean named
 * {@code springSessionRepositoryFilter}. In order to use this a single
 * {@link RedisConnectionFactory} must be exposed as a Bean.
private final RedisIndexedSessionRepository sessionRepository;

public SessionService(RedisTemplate<Object, Object> redisTemplate) {
    this.sessionRepository = new RedisIndexedSessionRepository(redisTemplate);
}