运行应用程序后检测到错误。我找不到任何问题,需要帮助。
软件包结构由配置和控制器组成。
弹簧靴 - 启动者data-redisredis.clients jedis 3.0.1
package com.arthur.springbootredis.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
@Configuration
public class RedisConfig {
@Bean
JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory jedisConnectionFactory = null;
try {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setDatabase(0);
redisStandaloneConfiguration.setHostName("localhost");
redisStandaloneConfiguration.setPort(6379);
jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);
jedisConnectionFactory.getPoolConfig().setMaxTotal(50);
jedisConnectionFactory.getPoolConfig().setMaxIdle(50);
} catch (RedisConnectionFailureException e) {
e.getMessage();
}
return jedisConnectionFactory;
}
@Bean
@ConditionalOnMissingBean(name = "redisTemplate")
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
template.setEnableTransactionSupport(true);
return template;
}
}
以下是错误内容
org.springframework.beans.factory.factory.beancreationexception:错误创建bean用名称" jedisconnection -factory"中定义的bean [com/arthur/arthur/arthur/arthur/arthur/arthur/arthur/springbootredis/config/redisconfig.class]:通过bean bean实例化通过工厂方法失败;嵌套的例外是org.springframework.beans.beanstantiationException:无法实例化[org.springframework.data.data.data.redis.connection.jediss.jedisconnectionfactory]:工厂方法:工厂方法'嵌套例外是java.lang.noclassdeffounderror:redis/clients/util/safeencoder
感谢您的阅读。
您正在尝试使用JEDIS 3.0.x,这对Jedis 2.x提供的API进行了破坏。JedisConnectionFactory
抛出了例外,该例外是Spring Data Redis的一部分,在撰写本文时,Spring Data Redis仅支持Jedis 2.x。对Jedis 3的支持已实施,但尚未发布。如果您想使用弹簧数据重新使用,则应暂时坚持使用JEDIS 2.X。对JEDIS 3.0的支持将在Spring Data Redis 2.2中发布,这是Spring Data Moore发行列车的一部分,并将包括在Spring Boot 2.2中。
自2019年7月以来,Spring Boot 2.X与Jedis 3.X兼容(有关更多信息,请参见升级到Jedis 3.1.0)。对于使用Gradle的人,这是我的组合:
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'redis.clients:jedis:3.1.0'
}