找不到 redis.clients.jedis.JedisPoolConfig 的类文件

问题描述 投票:0回答:1

我的 RedisConfig 类为:

@EnableRedisRepositories
public class RedisConfig {
    @Bean
    public JedisConnectionFactory jedisConnectionFactory() {
        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
        return new JedisConnectionFactory(redisStandaloneConfiguration);
    }
    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(jedisConnectionFactory());
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer());
        redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
        redisTemplate.setEnableTransactionSupport(true);
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }
}

当我尝试构建它时,我面临以下问题:

ava: cannot access redis.clients.jedis.JedisPoolConfig
  class file for redis.clients.jedis.JedisPoolConfig not found

现在,我尝试的是从

redisStandaloneConfiguration
中删除
JedisConnectionFactory
,然后返回新的
new JedisConnectionFactory()
。 虽然我没有收到上述错误,但我面临着一个新错误:

Error creating bean with name 'jedisConnectionFactory' defined in class path resource [com/iplbetting/iplbettingtracker/config/RedisConfig.class]: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: Factory method 'jedisConnectionFactory' threw exception with message: redis/clients/jedis/JedisClientConfig

当我进一步检查时,这是由于

java.lang.ClassNotFoundException: redis.clients.jedis.JedisClientConfig

造成的

我正在使用

spring-boot-starter-data-redis
,虽然我尝试添加版本3.x的jedis库,但我仍然面临同样的问题。

这是我的 pom.xml 中的依赖项:

<properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>io.lettuce</groupId>
                    <artifactId>lettuce-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--<dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.7.2</version>
        </dependency>-->
    </dependencies>

有我缺少的配置吗?

java spring-boot spring-data-redis jedis
1个回答
0
投票

可能是因为jedis依赖被注释掉了。

        <!--<dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.7.2</version>
        </dependency>-->

取消注释。

此外,还没有 jedis 3.7.2 版本。因此,请尝试一种有效且合适的方法。您可以在此处找到有效版本的列表。

例如:

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.10.0</version>
        </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.