springboot集成mongo
-
背景 linux版本:Kylin V10 docker版本:18.03 mongo版本:5.0.5
-
报错信息
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 172.18.48.233:8888. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:295) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:119) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.SaslAuthenticator.access$000(SaslAuthenticator.java:39) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:52) ~[mongodb-driver-core-3.6.3.jar:na]
... 9 common frames omitted
- 报错的配置
spring:
application:
name: spring-boot-mongodb
data:
mongodb:
username: test
password: 123456
uri: mongodb://IP:27017/test
- 经过查询资料,还是报错的配置
spring:
application:
name: spring-boot-mongodb
data:
mongodb:
uri: mongodb://test:123456@IP:27017/test
- 最终解决方案
spring:
application:
name: spring-boot-mongodb
data:
mongodb:
uri: mongodb://test:123456@IP:27017/test?authSource=admin&authMechanism=SCRAM-SHA-1
标签:集成,core,springboot,mongodb,jar,3.6,connection,com,mongo
From: https://blog.51cto.com/u_16082754/7012391