依靠DiscoveryClient来自动配置Redis吗?

问题描述

我正在尝试利用Redis的自动配置进行会话管理,并希望利用DiscoveryClient来解析Redis服务的实际主机和端口。

如果我创建自己的LettuceConnectionFactory bean并手动使用DiscoveryClient为我提供服务实例,那么一切都将正常工作。

但是,我希望完全避免这种情况,只希望在application.properties中指定属性,然后让DiscoveryClient发挥作用,并将“ redis-master”转换为正确的kubernetes服务URL:

spring.redis.url=redis://redis-master (or http://redis-master)

甚至只是主机,不必指定端口(如果我不提供端口,则默认为我不想要的端口)

spring.redis.host=redis-master

我的尝试失败了,但以下例外情况表明,显然redis:// redis-master并未转换为物理副本(因为似乎需要端口)。

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.session.RedisSessionConfiguration$SpringBootRedisHttpSessionConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Port out of range: -1
  at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE[]                                                                                                                                     
....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resolver
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794)  
....
Caused by: java.lang.IllegalArgumentException: Port out of range: -1 
     at io.lettuce.core.internal.LettuceAssert.isTrue(LettuceAssert.java:224) ~[lettuce-core-5.3.2.RELEASE.jar:5.3.2.RELEASE]
     at io.lettuce.core.RedisURI$Builder.redis(RedisURI.java:1083) ~[lettuce-core-5.3.2.RELEASE.jar:5.3.2.RELEASE] 
     at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.createRedisURIAndApplySettings(LettuceConnectionFactory.java:1132)
....

有没有想到RedisAutoConfiguration是否支持DiscoveryClient,以及是否有计划或附件允许它这样做?

我正在使用Spring Cloud Hoxton SR6。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...