java - 与 MongoDB 的 Jelastic 连接在远程 tomcat 上不起作用,但当本地 tomcat 连接到远程 Mongo 时正常

标签 java mongodb tomcat authentication jelastic

我在 Jelastic 上有一个环境,他们的支持没有帮助 :P

我使用 Java 8 和 MongoDB 2.6.4 安装了 Tomcat 7.0.55 对于 mongo,我还设置了一个外部 ip,这样我就可以从我的本地 tomcat 访问。

这里发生了什么, 我能够运行本地 Tomcat 和 Jelastic 远程 Mongo DB 但是当部署时,我从远程 mongo 得到这个日志

2015-01-07T22:57:29.637+0000 [conn22208]  authenticate db: easylend {authenticate: 1, user: "cre8tech", nonce: "xxx", key: "xxx" }
2015-01-07T22:57:29.638+0000 [conn22208] Failed to authenticate cre8tech@easylend with mechanism MONGODB-CR: AuthenticationFailed keymismatch

我 1000% 确定凭据是正确的,所以该方法用于记录,因为我能够在本地使用它到他们的远程 mongo + 我可以通过使用访问它

mongo XXXX.whelastic.net/{myDbName} --username {username} --password {password}

@Bean
@Override
public Mongo mongo() throws Exception {
    ServerAddress serverAdress = new ServerAddress(host, Integer.parseInt(port));  
    Mongo mongo = null;
    if (usr != null && !usr.isEmpty()) {
        MongoCredential credential = MongoCredential.createMongoCRCredential(usr, database, pwd.toCharArray());
        mongo = new MongoClient(serverAdress, Arrays.asList(credential));

    } else {
        mongo = new MongoClient(serverAdress);
    }

    mongo.setWriteConcern(WriteConcern.SAFE);

    return mongo;
}

登录tomcat就说无法认证

com.mongodb.CommandFailureException: { "serverUsed" : "********" , "code" : 18 , "ok" : 0.0 , "errmsg" : "auth fails"}

我的理论是远程 Jelastic tomcat 可能包含一些干扰我使用的 mongo 驱动程序的 jar/lib

谢谢你的帮助

最佳答案

不用再找了 我发现了问题

Jelastic 上的 tomcat 继承自一些 linux 命令,例如用于显示当前目录的 pwd 我在我的属性(property)中使用 pwd 来检索密码。 它不应该发生冲突,但确实发生了冲突,我将/opt/tomcat 作为密码而不是我的密码

这可能是你最终需要修复的东西,这样这些变量就不会与文件属性混合

解决方法是使用不同的属性名称

同样适用于 Amazon beantalk

谢谢

关于java - 与 MongoDB 的 Jelastic 连接在远程 tomcat 上不起作用,但当本地 tomcat 连接到远程 Mongo 时正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27850990/

相关文章:

java - 如何将 TortoiseSVN 与 Eclipse 一起使用

java - 在您的域中使用 Google 应用程序

mongodb - 对子数组文档执行 $sort

mongodb - 如何使用 go mongo-driver db.getUser()

java - "The type java.util.Map$Entry cannot be resolved"(tomcat6 + JDK7)

java - Spring servlet 适用于 IntelliJ 但不适用于 tomcat

tomcat - 从现有 WAR 文件创建 portlet

java - 如何设置组合框编辑器事件处理程序

c# - 如何在 Java swings GUI 应用程序中访问和使用 C# dll

mongodb - 遍历 MongoDB 中一个字段中的不同项