考虑在您的配置中定义类型为 'org.springframework.data.redis.connection.RedisConnectionFactory' 的 bean

Consider defining a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' in your configuration

我尝试使用 spring 会话,我从 git 下载这个项目 https://github.com/spring-guides/tut-spring-security-and-angular-js/tree/master/spring-session

我收到这个错误 应用程序启动失败


描述:

org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration 中方法 sessionRedisTemplate 的参数 0 需要找不到类型 'org.springframework.data.redis.connection.RedisConnectionFactory' 的 bean。

操作:

考虑在您的配置中定义类型为 'org.springframework.data.redis.connection.RedisConnectionFactory' 的 bean。

该错误具有误导性。您缺少一些依赖项。

compile 'redis.clients:jedis'
compile 'org.apache.commons:commons-pool2'

万一有人遇到 springboot 问题,可能是因为 pom.xml 中的依赖项丢失了

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

这个缺失的依赖项误导了我问题中的错误。