gpt4 book ai didi

java - 创建名称为 '...RedisHttpSessionConfiguration' 的 bean 时出错 : Initialization of bean failed

转载 作者:IT王子 更新时间:2023-10-29 06:12:28 26 4
gpt4 key购买 nike

我正在使用 Redis 并创建了 HttpSessionConfig 文件。这是我在

中的代码

HttpSessionConfig.java:

@EnableRedisHttpSession
public class HttpSessionConfig {

@Bean
public LettuceConnectionFactory connectionFactory() {

return new LettuceConnectionFactory();
}

@Bean
public HttpSessionIdResolver httpSessionStrategy() {
return HeaderHttpSessionIdResolver.authenticationInfo();
}

}

这是我的pom.xml 文件:

    <!-- Redis -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>

<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.3.1.Final</version>
</dependency>

但是我得到了错误:

Error creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration':

Initialization of bean failed

更多痕迹:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [bookstore/config/HttpSessionConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: io/lettuce/core/KeyValue

Caused by: org.springframework.beans.factory.BeanCreationException: Error

creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [bookstore/config/HttpSessionConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: Factory method 'connectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: io/lettuce/core/KeyValue

有人知道怎么解决吗???

最佳答案

在堆栈跟踪中,错误告诉我们

java.lang.NoClassDefFoundError: io/lettuce/core/KeyValue

所以手动添加依赖io.lettuce在你的 pom.xml 中

<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>5.1.7.RELEASE</version>
</dependency>

关于java - 创建名称为 '...RedisHttpSessionConfiguration' 的 bean 时出错 : Initialization of bean failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56823341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com