在对接一个投资项目时,启动项目出现如下错误,本来想直接问对接人,但他们没有出现这种情况,只能看一下。
由下面异常可以看出,Redis security建议禁用CONFIG命令,以便远程用户无法重新配置实例。
RedisHttpSessionConfiguration需要在初始化期间访问它。托管的Redis服务,在默认情况下禁用此命令,并且没有重新启用该命令的选项。
而且spring-session-redis需要使用键空间通知(keyspace notification)这个功能。
解决方式: 1. 配置notify-keyspace-events 2. 设置ConfigureRedisAction为NO_OP不加载CONFIG
其中在https://github.com/spring-projects/spring-session/issues/124,作者给出了比较详细的答案
下面看我的解决方式。
1. 开启notify-keyspace-events
2. 自定义配置加载ConfigureRedisAction为NO_OP
@Bean
public static ConfigureRedisAction configureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
下面是错误
2018-12-09 00:28:19.245 WARN 16648 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: ERR unknown command 'CONFIG'
2018-12-09 00:28:21.487 INFO 16648 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-12-09 00:28:21.496 INFO 16648 --- [ost-startStop-2] o.s.c.n.zuul.ZuulFilterInitializer : Stopping filter initializer context listener
2018-12-09 00:28:21.516 WARN 16648 --- [ost-startStop-2] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2018-12-09 00:28:21.531 INFO 16648 --- [ main] utoConfigurationReportLoggingInitializer :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is com.lambdaworks.redis.RedisCommandExecutionException: ERR unknown command 'CONFIG'