java 无法查找主机www.example.com的TXT记录Cluster0-XXXXX.mongodb.net

jtjikinw  于 2023-01-01  发布在  Java
关注(0)|答案(3)|浏览(130)
spring.data.mongodb.uri=mongodb+srv://XXXXXX:XXXXXXXXXXX@luster0-XXXXX.mongodb.net/test?retryWrites=true&w=majority
spring.data.mongodb.database=test

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoBootApplication': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDbFactoryDependentConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDbFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoDbFactorySupport]: Factory method 'mongoDbFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.MongoClient]: Factory method 'mongo' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up TXT record for host Cluster0-XXXXX.mongodb.net

vwoqyblh

vwoqyblh1#

我也遇到过同样的问题,没有找到相关的答案,我自己解决的,这是你的27017端口被你的防火墙封锁的问题,你需要在你的防火墙中打开这个端口的出站和入站。
适用于Windows的步骤:

  • 转到防火墙
  • 高级设置
  • 入站规则
  • 使用"操作"选项卡下的"新建规则"创建新规则
  • 选择端口
  • 选择TCP并指定端口号(27015、27016、27017)
  • 允许连接
  • 单击下一步
  • 添加新规则的名称完成

对出站规则执行相同的步骤。完成后,重新启动系统。

ymdaylpp

ymdaylpp2#

如果你还在寻找答案:
此问题是因为某些ISP阻止连接字符串。当使用默认DNS服务器与此类ISP时会发生此错误。
一个简单的测试,以找出是否ISP的问题,尝试切换到其他网络,看看它是否仍然存在。
如果你幸运的切换到一个不阻止连接字符串的ISP,那么你将连接到你的集群。如果没有,你可以尝试更改DNS配置以使用公共DNS服务器。
供参考:https://developers.google.com//speed/public-dns/docs/using

ktecyv1j

ktecyv1j3#

对我来说,由于长时间的不活动,集群被MongoDB Team暂停了。恢复后,它工作了。要恢复,请转到MongoDB Atlas集群 Jmeter 板,查看状态,然后单击恢复集群按钮。

相关问题