您好我是初级开发人员。
我试图在春季处理与Redis Sentinel相关的异常,但它不起作用。
我必须使用Redis群集,因此即使Redis Sentinel未连接也应该可以使用。
因此,在将Sentinel IP地址和端口(' sub.redis.sentinelipport')临时声明为' 0.0.0.0:0'之后,我在tomcat中运行以下代码。
public Map<Integer, JedisConnectionFactory> SubJedisConnectionFactory(
@Value("#{globalProps['sub.redis.mastername']}") String master,
@Value("#{globalProps['sub.redis.sentinelipport']}") String sentinel,
@Value("#{globalProps['sub.redis.password']}") String password,
@Value("#{globalProps['sub.redis.db']}") String strDbNum ) {
Map<Integer, JedisConnectionFactory> mapJedisConnectionFactory = new HashMap<Integer, JedisConnectionFactory>();
JedisConnectionFactory factory;
RedisSentinelConfiguration factory_sentinel;
for (String dbNum : strDbNum.split(",")) {
factory_sentinel= new RedisSentinelConfiguration(master, StringUtils.commaDelimitedListToSet(sentinel));
factory = new JedisConnectionFactory(factory_sentinel);
factory.setPassword(password);
factory.afterPropertiesSet();
factory.setDatabase(Integer.parseInt(dbNum));
mapJedisConnectionFactory.put(Integer.parseInt(dbNum), factory);
}
return mapJedisConnectionFactory;
}
然后,tomcat在&#39; factory.afterPropoertiesSet()&#39;中引发了一个异常,内容如下。
[2017-09-25 15:11:35.370] [INFO] com.example.pro.redis.RedisMasterSubTemplate MasterJedisConnectionFactory - ******* IN Master Jedis *******
25-Sep-2017 15:11:35.390 INFO [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Trying to find master from available Sentinels...
25-Sep-2017 15:11:35.438 WARNING [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Cannot connect to sentinel running @ 0.0.0.0:0. Trying next one.
[2017-09-25 15:11:35.438] [INFO] com.example.pro.redis.RedisMasterSubTemplate MasterJedisConnectionFactory - ******* Step3 .... master Jedis connection test....error msg : All sentinels down, cannot determine where is mymaster master is running... *******
25-Sep-2017 15:11:35.439 INFO [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Trying to find master from available Sentinels...
25-Sep-2017 15:11:35.439 WARNING [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Cannot connect to sentinel running @ 0.0.0.0:0. Trying next one.
[2017-09-25 15:11:35.439] [INFO] com.example.pro.redis.RedisMasterSubTemplate MasterJedisConnectionFactory - ******* Step3 .... master Jedis connection test....error msg : All sentinels down, cannot determine where is mymaster master is running... *******
25-Sep-2017 15:11:35.439 INFO [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Trying to find master from available Sentinels...
25-Sep-2017 15:11:35.440 WARNING [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Cannot connect to sentinel running @ 0.0.0.0:0. Trying next one.
[2017-09-25 15:11:35.440] [INFO] com.example.pro.redis.RedisMasterSubTemplate MasterJedisConnectionFactory - ******* Step3 .... master Jedis connection test....error msg : All sentinels down, cannot determine where is mymaster master is running... *******
25-Sep-2017 15:11:35.440 INFO [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Trying to find master from available Sentinels...
25-Sep-2017 15:11:35.440 WARNING [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Cannot connect to sentinel running @ 0.0.0.0:0. Trying next one.
[2017-09-25 15:11:35.440] [INFO] com.example.pro.redis.RedisMasterSubTemplate MasterJedisConnectionFactory - ******* Step3 .... master Jedis connection test....error msg : All sentinels down, cannot determine where is mymaster master is running... *******
[2017-09-25 15:11:35.445] [INFO] com.example.pro.redis.RedisMasterSubTemplate SubJedisConnectionFactory - ******* IN sub Jedis *******
25-Sep-2017 15:11:35.445 INFO [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Trying to find master from available Sentinels...
25-Sep-2017 15:11:35.445 WARNING [localhost-startStop-7] redis.clients.jedis.JedisSentinelPool.initSentinels Cannot connect to sentinel running @ 0.0.0.0:0. Trying next one.
[2017-09-25 15:11:35.450] [WARN] org.springframework.context.support.AbstractApplicationContext refresh - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentPushPopServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisMasterSubTemplate': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SubJedisConnectionFactory' defined in com.example.pro.redis.RedisMasterSubTemplate: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.Map]: Circular reference involving containing bean 'redisMasterSubTemplate' - consider declaring the factory method as static for independence from its containing instance. Factory method 'SubJedisConnectionFactory' threw exception; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738) [catalina.jar:8.0.28]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) [catalina.jar:8.0.28]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.28]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.28]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.28]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.28]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945) [catalina.jar:8.0.28]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1798) [catalina.jar:8.0.28]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_65]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisMasterSubTemplate': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SubJedisConnectionFactory' defined in com.example.pro.redis.RedisMasterSubTemplate: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.Map]: Circular reference involving containing bean 'redisMasterSubTemplate' - consider declaring the factory method as static for independence from its containing instance. Factory method 'SubJedisConnectionFactory' threw exception; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:461) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:435) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:559) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 26 common frames omitted
如何在没有连接Redis Sentinel的情况下运行程序?