1、报错复现
spring boot启动服务,报如下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/boot/autoconfigure/session/RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR config is disabled command

2、报错分析和解决
1、由于redis在腾讯云,按照官网的说明,想要用 config 命令,是只能用 config get,但是不能用 config set。修改腾讯云redis配置 notify-keyspace-events Ex ,原先为空,修改为Ex,重启服务,还是同样报错,该方法无效

2、application.yml配置文件中关闭redis健康检测,无效,我的spring-boot-autoconfigure版本为2.6.7,可能版本太低,redis没有health属性

3、代码中取消SpringSeesion对 CONFIG命令的操作,这个方法返回 ConfigureRedisAction.NO_OP,告诉 Spring 不要尝试启用 Redis 的 Keyspace Notifications,通过这种方式,你可以避免在 Redis 集群环境中未开启 Keyspace Notifications 导致的enableRedisKeyspaceNotificationsInitializer Bean 创建失败问题。再次重启服务,问题解决
@Configuration
public class HttpSessionConfig {
/**
* 解决redis集群环境没有开启Keyspace notifications导致的
*
* Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource
*
* */
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
}
1290

被折叠的 条评论
为什么被折叠?



