spring.data.mongodb.uri=mongodb+srv://XXXXXX:XXXXXXXXXXX@luster0-XXXXX.mongodb.net/test?retryWrites=true&w=majority
spring.data.mongodb.database=test
上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“mongoBootApplication”的 bean 时出错:通过字段“repository”表达的依赖关系不满足;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“userRepository”的bean时出错:设置bean属性“mongoOperations”时无法解析对bean“mongoTemplate”的引用;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建在类路径资源[org/springframework/boot/autoconfigure/data/mongo/MongoDbFactoryDependentConfiguration.class]中定义的名称为“mongoTemplate”的bean时出错:通过方法“表达的依赖关系不满足” mongoTemplate'参数0;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建类路径资源中定义的名称为“mongoDbFactory”的bean时出错[org/springframework/boot/autoconfigure/data/mongo/MongoDbFactoryConfiguration.class]:通过工厂方法实例化Bean失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.mongodb.core.MongoDbFactorySupport]:工厂方法“mongoDbFactory”抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]中定义的名为“mongo”的bean时出错:通过工厂方法实例化Bean失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.mongodb.MongoClient]:工厂方法“mongo”抛出异常;嵌套异常是 com.mongodb.MongoConfigurationException:无法查找主机 Cluster0-XXXXX.mongodb.net 的 TXT 记录
最佳答案
我遇到了同样的问题,但没有找到任何相关答案。我自己解决了。这是您的端口 27017 被防火墙阻止的问题。您需要在防火墙中打开此端口的出站和入站。
Windows 的步骤:
- 进入防火墙
- 高级设置
- 入站规则
- 使用“操作”选项卡下的“新建规则”创建新规则
- 选择端口
- 选择 TCP 并指定端口号 (27015,27016,27017)
- 允许连接
- 点击“下一步”
- 为新规则完成添加名称
对出站规则执行相同的步骤。 完成后,重新启动系统。
关于java - 无法查找主机 Cluster0-XXXXX.mongodb.net 的 TXT 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61886714/