小编최혜민*_*최혜민的帖子

我不知道为什么会发生这种情况。jedis 创建名为“jedisConnectionFactory”的 bean 时出错

运行应用程序后检测到错误。我找不到任何问题,我需要帮助。

包结构由config和controller组成。

spring-boot-starter-data-redis redis.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>(); …
Run Code Online (Sandbox Code Playgroud)

redis jedis spring-boot

2
推荐指数
1
解决办法
9253
查看次数

标签 统计

jedis ×1

redis ×1

spring-boot ×1