英文:
UnknownHostException: failed to resolve 'my-redis-host' after 6 queries after switching from Jedis to Redisson
问题
切换从Jedis到Redisson后,我遇到了一个类似的问题:
- https://github.com/redisson/redisson/issues/1693
- https://github.com/redisson/redisson/issues/1486
- https://github.com/redisson/redisson/issues/1646
- https://github.com/redisson/redisson/issues/1625
我尝试了我提到的问题的评论中的所有解决方案和解决方法,但我仍然遇到以下错误:
[java] 20:46:08.537 ERROR [main] o.s.web.context.ContextLoader (ContextLoader.java:313): Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyRedissonConnectionFactory': Invocation of init method failed; nested exception is java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
...
[java] Caused by: java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
...
[java] 20:46:08.606 WARN [main] o.e.jetty.webapp.WebAppContext (WebAppContext.java:554): Failed startup of context o.e.j.w.WebAppContext@19f1f330{/,} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRedissonConnectionFactory': Invocation of init method failed; nested exception is java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
...
[java] Caused by: java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
...
我的配置如下:
String host = "my-redis-host";
int port = 6379;
Config config = new Config();
config.useSingleServer()
.setAddress(String.format("redis://%s:%s", host, port))
.setPassword("password");
RedissonClient redissonClient = Redisson.create(config);
return new RedissonConnectionFactory(redissonClient);
在docker-compose
文件中的服务定义如下:
my-redis-host:
image: 'bitnami/redis:latest'
hostname: redis
container_name: contaner_my-redis-host
environment:
- REDIS_PASSWORD=password
ports:
- '6379:6379'
版本:
compile group: 'org.redisson', name: 'redisson-spring-data-21', version: '3.12.0'
compile group: 'io.netty', name: 'netty-common', version: '4.1.47.Final'
我做错了什么?如何修复这个问题?
英文:
After switching from Jedis to Redisson I have an issue which looks similar
- https://github.com/redisson/redisson/issues/1693
- https://github.com/redisson/redisson/issues/1486
- https://github.com/redisson/redisson/issues/1646
- https://github.com/redisson/redisson/issues/1625
I tried all solutions and workarounds from comments of issues I mentioned but I still experience
[java] 20:46:08.537 ERROR [main] o.s.web.context.ContextLoader (ContextLoader.java:313): Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyRedissonConnectionFactory': Invocation of ini
t method failed; nested exception is java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
[java] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
[java] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
[java] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
[java] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
[java] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
[java] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
[java] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
[java] at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)
[java] at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)
[java] at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[java] at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[java] at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
[java] at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.server.Server.start(Server.java:419)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.server.Server.doStart(Server.java:386)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at my.WebAppRunner.startServer(WebAppRunner.java:127)
[java] Main.main(Main.java:63)
[java] Caused by: java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
[java] at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:925)
[java] at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:884)
[java] at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:356)
[java] at io.netty.resolver.dns.DnsResolveContext.onResponse(DnsResolveContext.java:519)
[java] at io.netty.resolver.dns.DnsResolveContext.access$400(DnsResolveContext.java:64)
[java] at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:400)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:570)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:549)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490)
[java] at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615)
[java] at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604)
[java] at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
[java] at io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:201)
[java] at io.netty.resolver.dns.DnsQueryContext.finish(DnsQueryContext.java:193)
[java] at io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1217)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[java] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[java] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
[java] at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
[java] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
[java] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[java] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[java] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[java] at java.lang.Thread.run(Thread.java:745)
[java]
[java] 20:46:08.606 WARN [main] o.e.jetty.webapp.WebAppContext (WebAppContext.java:554): Failed startup of context o.e.j.w.WebAppContext@19f1f330{/,} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRedissonConnectionFactory': Invocation of init method failed; nested except
ion is java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
[java] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
[java] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
[java] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
[java] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
[java] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
[java] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
[java] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
[java] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
[java] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
[java] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
[java] at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558)
[java] at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370)
[java] at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
[java] at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
[java] at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
[java] at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
[java] at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
[java] at org.eclipse.jetty.server.Server.start(Server.java:419)
[java] at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
[java] at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
[java] at org.eclipse.jetty.server.Server.doStart(Server.java:386)
[java] at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
[java] at my.WebAppRunner.startServer(WebAppRunner.java:127)
[java] at my.Main.main(Main.java:63)
[java] Caused by: java.net.UnknownHostException: failed to resolve 'my-redis-host' after 6 queries
[java] at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:925)
[java] at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:884)
[java] at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:356)
[java] at io.netty.resolver.dns.DnsResolveContext.onResponse(DnsResolveContext.java:519)
[java] at io.netty.resolver.dns.DnsResolveContext.access$400(DnsResolveContext.java:64)
[java] at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:400)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:570)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:549)
[java] at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490)
[java] at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615)
[java] at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604)
[java] at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
[java] at io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:201)
[java] at io.netty.resolver.dns.DnsQueryContext.finish(DnsQueryContext.java:193)
[java] at io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1217)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[java] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
[java] at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
[java] at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
[java] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
[java] at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
[java] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
[java] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
[java] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
[java] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
[java] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
[java] at java.lang.Thread.run(Thread.java:745)
my config looks like:
String host = "my-redis-host";
int port = 6379;
Config config = new Config();
config.useSingleServer()
.setAddress(String.format("redis://%s:%s", host, port))
.setPassword("password");
RedissonClient redissonClient = Redisson.create(config);
return new RedissonConnectionFactory(redissonClient);
service definition in docker-compose
file:
my-redis-host:
image: 'bitnami/redis:latest'
hostname: redis
container_name: contaner_my-redis-host
environment:
- REDIS_PASSWORD=password
ports:
- '6379:6379'
versions:
compile group: 'org.redisson', name: 'redisson-spring-data-21', version: '3.12.0'
compile group: 'io.netty', name: 'netty-common', version: '4.1.47.Final'
What do I wrong ? How to fix it ?
答案1
得分: 1
确保您的本地 DNS 正确解析 my-redis-host
。
英文:
Make sure your local dns resolves my-redis-host
correctly
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论