springboot集成redisson启动报错:Unable to connect to Redis server

redis未配置密码时springboot集成redisson启动报错Unable to connect to Redis server。

application.yml配置:

spring:
  redis:
    host: 127.0.0.1
    port: 6379
    password:

方式一:
maven依赖:


    org.redisson
    redisson-spring-boot-starter
    3.9.1

重新实现实现RedissonClient:

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private Integer port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://" + host + ":" + port);
        if (StringUtils.isNotEmpty(password)) {
            config.useSingleServer().setPassword(password);
        }
        return Redisson.create(config);
    }
}

方式二:
maven依赖:


    org.redisson
    redisson
    3.8.2

重新实现实现Redisson :

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private Integer port;

    @Value("${spring.redis.password}")
    private String password;

    @Bean
    public Redisson getClient () {
        Config config = new Config();

        config.useSingleServer().setAddress("redis://" + host + ":" + port);
//                                .setPassword(password);
        if (StringUtils.isNotEmpty(password)) {
            config.useSingleServer().setPassword(password);
        }

        return (Redisson)Redisson.create(config);
    }
}

你可能感兴趣的:(redis)