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.1port: 6379password:方式一:maven依赖:<dependency><groupId>org.redisson</grou
·
redis未配置密码时springboot集成redisson启动报错Unable to connect to Redis server。
application.yml配置:
spring:
redis:
host: 127.0.0.1
port: 6379
password:
方式一:
maven依赖:
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.9.1</version>
</dependency>
重新实现实现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依赖:
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.8.2</version>
</dependency>
重新实现实现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);
}
}
更多推荐
已为社区贡献3条内容
所有评论(0)