gpt4 book ai didi

java - MongoDb + Java 驱动程序出现奇怪的错误

转载 作者:行者123 更新时间:2023-12-01 15:41:07 24 4
gpt4 key购买 nike

我正在使用 MongoDb 作为数据库构建 Resteasy 服务。

它在我的 Mac 上完美运行,但在测试服务器的 Fedora 15 上,它会引发如下错误:

    07:20:15,060 WARNING [com.mongodb.tcp] (http--0.0.0.0-8000-1) Exception determining maxBSON size using0: java.io.IOException: couldn't connect to [eid/67.215.65.132:27017] bc:java.net.ConnectException: Connection timed out
at com.mongodb.DBPort._open(DBPort.java:228) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.go(DBPort.java:112) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.go(DBPort.java:93) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.findOne(DBPort.java:146) [mongo-2.7.0.jar:]
at com.mongodb.DBPort.runCommand(DBPort.java:157) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:457) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:444) [mongo-2.7.0.jar:]
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:209) [mongo-2.7.0.jar:]
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor._check(DBCursor.java:369) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor._hasNext(DBCursor.java:498) [mongo-2.7.0.jar:]
at com.mongodb.DBCursor.hasNext(DBCursor.java:523) [mongo-2.7.0.jar:]
at eid.ariel.TestService.getAllUsers(TestService.java:39) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_22]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.6.0_22]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.6.0_22]
at java.lang.reflect.Method.invoke(Method.java:616) [:1.6.0_22]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.2.1.GA.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
at java.lang.Thread.run(Thread.java:679) [:1.6.0_22]

访问数据库的代码是:

public List<DBObject> getAllUsers() throws UnknownHostException, MongoException, FileNotFoundException{
Mongo mongo = new Mongo("localhost");
DBCollection collection = mongo.getDB("eid_security_dev").getCollection("users");
DBCursor cur = collection.find();
List<DBObject> result = new ArrayList<DBObject>();
while (cur.hasNext()){

result.add(cur.next());
}
return result;
}

使用 Mongo 驱动程序 2.7.0 和 mongodb 服务器 2.0.0

最佳答案

java.io.IOException: couldn't connect to [eid/67.215.65.132:27017] bc:java.net.ConnectException: Connection timed out

您的数据库客户端似乎无法连接到 MongoDB 服务器。需要调查的一些事情:

  • 确保您的数据库服务器已启动并正在运行。

  • 使用 mongo shell 验证您的 MongoDB 服务器是否完全正常运行。

  • 67.215.65.132 是公共(public) IP 地址。 localhost 通常应解析为地址为 127.0.0.1 或类似地址的环回接口(interface)。尝试直接使用 127.0.0.1,因为使用公共(public) IP 可能意味着存在阻止访问数据库服务器端口的防火墙规则。连接超时而不是被拒绝使这种情况很有可能发生。

关于java - MongoDb + Java 驱动程序出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8021897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com