0

我的游戏!应用程序有一个模块,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)
4

2 回答 2

0

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

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

于 2012-02-07T01:53:34.133 回答
-1

这个“身份验证两次异常”被抛出

{@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);
于 2012-03-14T03:30:29.293 回答