【问题标题】:playMorphia with mongoLAB IllegalStateException: can't call authenticate twice on the same DBObjectplayMorphia with mongoLAB IllegalStateException:不能在同一个 DBObject 上调用两次身份验证
【发布时间】:2012-03-14 11:30:29
【问题描述】:

我的游戏!应用程序有一个模块,morphia。我的数据库是 mongolab(在 AWS 上)。它第一次编译并运行。然后将在所有后续请求中抛出此 DB 身份验证异常。有谁知道 playmorphia 是否会尝试对每个请求进行重新身份验证?非常感谢任何帮助。谢谢。

Caused by: java.lang.IllegalStateException: can't call authenticate twice on the same DBObject
    at com.mongodb.DB.authenticate(DB.java:437)
    at play.modules.morphia.MorphiaPlugin.initMorphia_(MorphiaPlugin.java:368)
    at play.modules.morphia.MorphiaPlugin.onApplicationStart(MorphiaPlugin.java:444)
    at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:480)
    at play.Play.start(Play.java:515)

【问题讨论】:

    标签: playframework morphia mlab


    【解决方案1】:

    好吧,在播放开始时调用 db 身份验证。问题是当您在开发模式下运行时,播放可能会在您的 java 源代码和查看源代码中的每次代码更改时重新启动。

    我之前从未遇到过这个问题,因为我一直在 trusted environment 中使用 mongodb。但是应该避免这种问题,可能只是简单地尝试/捕获并忽略。您能否向https://github.com/greenlaw110/play-morphia/issues/new 提交问题?

    【讨论】:

    • 我怀疑您对代码更改时的重新启动连接是正确的。我会把它贴在你的github上。感谢您的快速周转。
    【解决方案2】:

    这个“认证两次异常”被抛出

    {@link com.mongo.DB#authenticate(String username, char[] passwd )}
    

    它在类 DatastoreImpl 的构造函数中使用 user&pass 调用。 所以,如果你在同一个数据库中两次 new DatastoreImpl(),就会发生这个异常。

    你可以试试下面的代码,希望对你有帮助:

    DatastoreImpl ds = !this.mongo.getDB(dbName).isAuthenticated()? new DatastoreImpl(morphia, mongo, dbName, userName,asswd.toCharArray()) : new DatastoreImpl(morphia, mongo, dbName);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 2016-01-01
      • 2019-08-11
      • 1970-01-01
      • 2018-04-29
      • 2014-01-29
      • 2018-01-01
      相关资源
      最近更新 更多