简体   繁体   English

将Spring Boot应用程序连接到mongodb

[英]connect spring boot app to mongodb

i'm trying to connect my spring boot app to a remote mongodb database. 我试图将我的Spring Boot应用程序连接到远程mongodb数据库。 When i run my app i got this error: 当我运行我的应用程序时,出现此错误:

2017-05-25 15:22:57.829 INFO 4532 --- [*******:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server mongodb-server-address:27017 2017-05-25 15:22:57.829信息4532 --- [*******:27017] org.mongodb.driver.cluster:连接到服务器mongodb-server-address:27017时监视线程异常

com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na] at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na] at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na] at java.lang.Thread.run(Unknown Source) [na:1.7.0_79] Caused by: java.net.ConnectException: Connection refused: connect com.mongodb.MongoSocketOpenException:com.mongodb.connection.SocketStream.open(SocketStream.java:63)〜[mongodb-driver-core-3.4.2.jar:na]处的com.mongodb.connection.InternalStreamConnection处的异常打开套接字.open(InternalStreamConnection.java:115)〜[mongodb-driver-core-3.4.2.jar:na] at com.mongodb.connection.DefaultServerMonitor $ ServerMonitorRunnable.run(DefaultServerMonitor.java:113)〜[mongodb-driver- core-3.4.2.jar:na]位于java.lang.Thread.run(未知来源)[na:1.7.0_79]原因:java.net.ConnectException: 连接被拒绝:connect

By default MongoDB only binds to the loopback interface which makes it only accessible from localhost. 默认情况下,MongoDB仅绑定到回送接口,这使得它只能从本地主机访问。 To change that you need to edit this line in mongod.conf file; 要更改,您需要在mongod.conf文件中编辑此行;

you can change it to allow LAN and local connections or you can remove or comment out that line bind_ip = 127.0.0.1 to allow all connections. 您可以更改它以允许LAN和本地连接,也可以删除或注释掉该行bind_ip = 127.0.0.1以允许所有连接。

For more info : MongoDB – Allow remote access 有关更多信息: MongoDB –允许远程访问

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM