spring - 春季启动上下文创建错误,以防在春季 Redis 集群配置中无法访问一个主节点
问题描述
我正在使用带有redis配置的spring boot
@Bean
public RedisConnectionFactory jedisConnectionFactory() {
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(nodes);
/*username & password check for security */
return new JedisConnectionFactory(redisClusterConfiguration);
}
这里是配置
cache.redis.cluster.nodes=127.0.0.1:60001,127.0.0.1:60002,127.0.0.1:60003,127.0.0.1:60004,127.0.0.1:60005,127.0.0.1:60006
此配置工作正常,但在某些情况下,如果 redis 集群中的一个主节点关闭,然后我重新启动应用程序,上下文创建会失败,但会出现一些异常......
*******package name******/RedisClusterConfig.class]: Invocation of init method failed; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:155)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:135)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5144)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 10 more
在它给出了一些与我项目的其他组件相关的更多异常之后立即......
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name XXX
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为 MMM 的 bean 时出错springframework.beans.factory.UnsatisfiedDependencyException:创建名为 ZZZ org.springframework.beans.factory.UnsatisfiedDependencyException 的 bean 时出错:创建名为 ZZZ org.springframework.beans.factory.UnsatisfiedDependencyException 的 bean 时出错:创建名为 YYY org.springframework 的 bean 时出错。 beans.factory.UnsatisfiedDependencyException:创建名称为 YYY org.springframework.beans.factory.UnsatisfiedDependencyException 的 bean 时出错:创建名称为 XXX org.springframework.beans.factory 的 bean 时出错。UnsatisfiedDependencyException:创建名称为 XXX 的 bean 时出错
我无法理解也找不到根本原因,因为我的期望是,如果 redis 集群中的任何主节点无法访问,它将继续进行上下文初始化过程。这就是为什么我们称它为“集群”,它应该与其他健康节点一起继续。
有什么遗漏的部分可以帮助我吗?
谢谢
解决方案
推荐阅读
- python - 在 python 中导入比特币库的问题
- javascript - 不使用函数的 AJAX 中的 setInterval
- mysql - 如何从 Lambda 访问在 EC2 实例上运行的 MySQL?
- python - 散点图,其中 y 是分类的,x 是集合列表
- ktor - Ktor 响应流
- c++ - #ifdef 在同一个头文件中返回不同的值
- javascript - findDOMNode 在 StrictMode React 材质 UI 中已弃用
- c - 为什么我无法从 addr2line 获取源代码行?
- typo3 - 您如何将 Fluid 分页小部件用于菜单?
- c++ - C ++ - 如何编写适用于临时且不分配的函数