在 Spring 中使用 Java 驱动程序出现无休止的 MongoDB ReplicaSetStatus 更新程序异常
我刚刚在 Glassfish 上部署了一个 Spring Web 应用程序。 这个应用程序包含一个用于 Mongo 对象的注入 Spring bean,这是非常基本的,它看起来像这样:
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="127.0.0.1" />
<constructor-arg value="27017" />
</bean>
我启动我的 Web 应用程序,然后使用这个 Mongo 对象来查询数据库并插入记录等等......一切正常。
但在我的 server.log 文件中,我收到了无穷无尽的 SEVERE
错误消息。它们是 NullPointerException 和 IOException。它们似乎与 ReplicaSetStatus 有关,但我不知道为什么它不断尝试连接,它是默认打开的吗?
有谁知道造成这些的原因是什么? 我怎样才能解决这个问题,或者阻止导致这些问题的任何原因?
// 编辑: 部署应用程序后,异常立即开始。但当我禁用我的应用程序,甚至取消部署它时,它们不会停止。
这些消息不断被写入,但据我所知,只有 4 种类型的错误:
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: 27017:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb..updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)
|#]
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: localhost:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 127.0.0.1:27017
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 27017:27017
java.io.IOException: couldn't connect to [/0.0.105.137:27017] bc:java.net.SocketException: Network is unreachable: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
I just deployed a Spring web application onto Glassfish.
This app contains an injected Spring bean for the Mongo object, which is pretty basic, it just looks like this:
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="127.0.0.1" />
<constructor-arg value="27017" />
</bean>
I fire up my web app, then use this Mongo object to query the db and insert records and whatnot.. and everything works fine.
But in my server.log file I get and endless stream of SEVERE
error messages. They are NullPointerException
s and IOException
s. They appear to have something to do with ReplicaSetStatus, but I don't know why it keeps trying to connect, is it turn on be default?
Does anyone know what causes these?
How can I fix the problem, or stop whatever is causing them?
// EDIT:
The exceptions start immediately after I deploy my application. But they do not stop when I disable my application, or even undeploy it.
These messages just get written constantly, but from what I can see theres only 4 types of errors:
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: 27017:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb..updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)
|#]
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: localhost:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 127.0.0.1:27017
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 27017:27017
java.io.IOException: couldn't connect to [/0.0.105.137:27017] bc:java.net.SocketException: Network is unreachable: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Spring 上下文文件中更改 Mongo bean 定义,如下所示:
如果省略 type 属性,则会调用另一个 Mongo 类构造函数,其中参数是 com.mongodb.ServerAddress 类型的实例,以及 27017< /strong> 被视为主机名,并且 InetAddress.getAllByName( host ) 解析为此 IP 0.0.105.137。
Change your Mongo bean definition in Spring context file as here:
If you omit type attributes, another Mongo class constructor is invoked, where arguments are instances of com.mongodb.ServerAddress type, and 27017 is treated as a hostname and InetAddress.getAllByName( host ) resolves to this IP 0.0.105.137.