当前位置: 首页 > 知识库问答 >
问题:

在集群模式下使用SSL连接到AWS弹性缓存时,Spring Boot中出现异常

薄龙光
2023-03-14

我们正在使用spring boot starter data redis(1.5.9.RELEASE)以集群模式连接到AWS弹性缓存(redis)。

如果我们不启用Redis Auth(密码)并在AWS弹性缓存中加密传输中的数据,一切都很好。

当数据传输和启用redis auth时,我们得到连接重置异常。

configured with below environment variables.

spring.redis.cluster.nodes=node1**.com:6379,node2***.com:6379

spring.redis.ssl=true

spring.redis.password=******

以下例外情况:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.config.internalCacheAdvisor' defined in class path resource [org/springframework/cache/annotation/ProxyCachingConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor]: Factory method 'cacheAdvisor' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheAutoConfigurationValidator': Unsatisfied dependency expressed through field 'cacheManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cacheManager' defined in class path resource [org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.class]: Unsatisfied dependency expressed through method 'cacheManager' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class]: Unsatisfied dependency expressed through method 'redisTemplate' parameter 0; 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/RedisAutoConfiguration$RedisConnectionConfiguration.class]: Invocation of init method failed; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:70)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:346)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)

更多异常详情:

caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset
    at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
    at redis.clients.jedis.Protocol.process(Protocol.java:151)
    at redis.clients.jedis.Protocol.read(Protocol.java:215)
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
    at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:96)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:117)
    at redis.clients.jedis.BinaryClient.auth(BinaryClient.java:564)
    at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2138)
    at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:36)
    at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:17)
    at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:24)
    at redis.clients.jedis.BinaryJedisCluster.<init>(BinaryJedisCluster.java:54)
    at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:93)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:306)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:280)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:241)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)

共有1个答案

邹海荣
2023-03-14

您需要为连接定义至少一个redis模板。类似的事情(取决于你的客户)

@Bean
JedisConnectionFactory jedisConnectionFactory() {
    return new JedisConnectionFactory();
}

@Bean
public RedisTemplate<String, Object> redisTemplate() {
    RedisTemplate<String, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(jedisConnectionFactory());
    return template;
}
 类似资料:
  • 当我使用带SSL的apache camel连接到Kafka集群时,我面临以下问题,请任何人帮助解决这个问题 javax . net . SSL . SSL handshake异常:sun . security . validator . validator异常:PKIX路径构建失败:sun . security . provider . certpath . suncertpathbuildere

  • 我正在使用asmack-android-16为我的聊天应用程序。有时,在创建连接,我得到SSL异常,然后我无法登录服务器。我的服务器正在对连接使用SSL身份验证。有人能帮帮我吗?我已经挣扎了好几周了 以下是我的连接配置: XMPPConnection连接=new XMPPConnection(连接配置);connection.connect (); // 调用此行会给我异常,尽管已创建连接。 以下

  • 在elasticsearch和kibana中启用ssl通信工作良好,但logstash无法连接elasticsearch,但我可以卷曲elasticsearch urlhttps://localhost:9200也没有防火墙阻止,我已经生成了打开的ssl证书和密钥文件并保存在elasticsearch中 弹性搜索配置文件 logstash日志文件

  • 我正在尝试连接到AWS Elastic Cache Redis群集,我不断收到此消息,但仍然收到移动12218 ip:6379的错误 以下是代码 https://www.npmjs.com/package/redis-redis:^4.0.1 输出: 但当我等待客户的时候。获取(键)或等待客户端。设置(键,值)我得到移动的错误。 我甚至遵循了这个https://github.com/redis/n

  • 我正在使用SunPKCS11连接到HSM设备。我有一些运行完美的单元测试(实际上他们会进行一些签名和验证),但是,当我将应用程序部署到tomcat或jetty时,我会得到这个异常(这个异常是在jetty中部署期间引发的,tomcat的异常是相似的): 下面是我如何实例化SunPKCS11的: 只是为了添加一些细节,我在windows server 2012上使用了64位java8。 更新1:我刚刚

  • 我使用的是弹性缓存单节点碎片redis 4.0更高版本。 我启用了在途加密,并给了redis身份验证令牌。 我用这个链接创建了一个堡垒主机 https://aws.amazon.com/premiumsupport/knowledge-center/elasticache-connect-redis-node/ 我可以通过以下方式连接到弹性缓存redis节点 redis cli-h hostnam