springboot 集成redis , 单机版正常启动,没有这个问题, redis集群启动报:
错误信息
Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR argument wrong
报错原因
redis集群环境没有开启Keyspace notifications
解决办法
两步:
- 修改redis 配置
通过命令方式修改
> redis-cli config set notify-keyspace-events Egx
直接修改配置redis.conf文件
notify-keyspace-events Egx
可视化工具也可以直接修改,不用命令行
- 在 RedisConfiguration 类中增加一个 Bean
@Configuration
public class RedisConfiguration{
/**
* 解决redis集群环境没有开启Keyspace notifications导致的
*
* Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource
*
* */
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}
redis 集群和单机版需要修改的就这两个地方,其他配置不需要修改