春季-CannotGetMongoDbConnectionException:无法验证数据库

在副本集的Mongo Shell中,使用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后停止.

上一篇:linux网络编程涉及的函数


下一篇:Veeam Backup&Replication Virtual Lab工作原理和配置