账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    spring boot连接mongodb报错
    56
    0

    刚开始学习mongodb,编写了一个简单的spring boot程序连接mongo
    ,使用如下配置可以正确连接到mongo:

    spring.data.mongodb.host=10.159.14.19
    spring.data.mongodb.port=9001
    spring.data.mongodb.authentication-database=admin
    spring.data.mongodb.database=esign
    spring.data.mongodb.username=esign_write
    spring.data.mongodb.password=NTc2OTQ1YjcwN2Z

    但是使用下面的配置就会报错:

    spring.data.mongodb.uri=mongodb://esign_write:NTc2OTQ1YjcwN2Z@10.159.14.19:9001/esign
    spring.data.mongodb.authentication-database=admin

    错误信息如下:

    com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='esign_write', source='esign', password=<hidden>, mechanismProperties={}}
        at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:61) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:99) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:44) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongodb-driver-core-3.2.2.jar:na]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
    Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 10.159.14.19:9001. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
        at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:95) ~[mongodb-driver-core-3.2.2.jar:na]
        at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:45) ~[mongodb-driver-core-3.2.2.jar:na]
        ... 6 common frames omitted

    这个是什么原因?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 泛少 普通会员 1楼

      在Spring Boot中连接MongoDB时,可能会出现以下错误:

      1. org.springframework.boot.autoconfigure.context.ConfigurationPropertiesResource - 应该是org.springframework.boot.context.properties.ConfigurationPropertiesResource,而不是org.springframework.boot.context.properties.ConfigurationPropertiesResource

      2. MongoDBClientConfig - 应该是MongoDBClientConfig,而不是MongoDBClientConfig

      3. MongoDBException - 应该是MongoDBException,而不是MongoDBException

      4. MongoDBAuthenticationException - 应该是MongoDBAuthenticationException,而不是MongoDBAuthenticationException

      5. MongoDBConnectionException - 应该是MongoDBConnectionException,而不是MongoDBConnectionException

      解决这些问题的方法是检查你的配置文件,确保它们的名称正确。如果你的配置文件包含错误的名称,你可能需要替换它们。同时,你还需要检查你的数据库连接设置,确保它们是正确的。

      如果你使用的是Maven,你可能需要检查你的pom.xml文件,确保你的数据库驱动和配置正确。你也可以尝试添加错误处理代码,以处理可能出现的错误。

      如果你在使用MongoDBTemplate时遇到问题,你可以尝试添加@AutoConfigureMongoDB注解,以自动配置MongoDB。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部