前言
一直听说Redisson分布式锁好用,终于在项目上使用了!在本地测试完毕,一上测试环境,运维就反馈服务没起来,拉日志一看,是以下报错
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restUtil' defined in URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/com/xxx/util/RestUtil.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getRedisson' defined in class path resource [com/xxx/config/RedissonConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'getRedisson' threw exception; nested exception is org.redisson.client.RedisConnectionException: java.net.UnknownHostException: failed to resolve 'redis-service.middleware.svc' after 3 queries
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
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:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
主要报错信息是
Factory method 'getRedisson' threw exception; nested exception is org.redisson.client.RedisConnectionException:
java.net.UnknownHostException: failed to resolve 'redis-service.middleware.svc' after 3 queries
于是乎,上github看了一下,发现这还是一个比较热门dns解析失败的问题,好多人都遇到了同样的问题。想着开源项目,这么多人提出问题,肯定已经修复了,于是将3.16.0版本的Redisson升级到最新版本3.21.3,再上测试环境发现还是启动不起来,还是同样的报错。文章来源:https://www.toymoban.com/news/detail-755899.html
于是就在那翻Redisson的Issues,试了好多种配置都不管。最后在https://github.com/redisson/redisson/issues/1625发现有个人提到,是这个提交引发的bug
而这个提交确实有dns相关的内容(提交链接)
因为以上代码的提交版本是3.5.6
,于是乎将版本回退为3.5.5
之后,问题解决。由于是刚刚使用Redisson,使用的地方不多,所以暂时采用这个方法解决了。猜想这个问题可能只在k8s环境使用k8s自带的Rredis域名时才有问题,正常的域名应该不会有问题吧?
各位如果有更好的解决办法,希望能够评论区留言一下!文章来源地址https://www.toymoban.com/news/detail-755899.html
到了这里,关于记一次Redisson连接k8s环境Redis报UnknownHostException-域名解析错误问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!