spring - 无法获取 MongoDbConnectionException : Failed to authenticate to database

标签 spring mongodb replication spring-data-mongodb

在replica-set Mongo Shell中,use products;db.auth('worker'.'a*******6');没问题,但是在spring-data中-mongondb,我遇到了以下问题:

Exception in thread "main" org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [products], username = [worker], password = [a*******6]
    at org.springframework.data.mongodb.core.ReflectiveDbInvoker.authenticate(ReflectiveDbInvoker.java:83)
    at org.springframework.data.mongodb.core.MongoDbUtils.doGetDB(MongoDbUtils.java:127)
    at org.springframework.data.mongodb.core.MongoDbUtils.getDB(MongoDbUtils.java:94)
    at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:197)
    at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:185)
    at org.springframework.data.mongodb.core.MongoTemplate.getDb(MongoTemplate.java:1595)
    at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:441)
    at org.springframework.data.mongodb.core.MongoTemplate.doCreateCollection(MongoTemplate.java:1612)
    at org.springframework.data.mongodb.core.MongoTemplate.createCollection(MongoTemplate.java:492)
    at com.qixin.appmarket.service.test.TestMongodb.main(TestMongodb.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

最佳答案

尝试将 spring-data-mongodb 更新到最新版本。我在使用版本 1.7.2.RELEASE 时收到身份验证错误,但在更新到 1.8.0.RELEASE 后它停止了。

关于spring - 无法获取 MongoDbConnectionException : Failed to authenticate to database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29890785/

相关文章:

java - 具有 JPA 持久性的 Spring 状态机 - 存储库使用

node.js - 跨服务器的 NodeJS 匹配

node.js - 如何使用 Mongoose 和 NodeJS 在 MongoDB 中保存嵌套数组

javascript - Mongoose 不返回空对象的属性

MySQL 复制 - 一个网站,许多服务器,不同的大陆

MySQL 和 Windows Vista : How to setup replication?

java - spring security : NoSuchBeanDefinitionException: No qualifying bean of type [org. springframework.security.config.annotation.ObjectPostProcessor] 找到

Spring security BasicAuthenticationFilter 返回 403 而不是 401

mysql - Google Cloud MySQL 和主主复制

spring - 为什么 JpaRepository.delete() 在删除实体之前检索它?