简体   繁体   English

Spring 多个打开的连接

[英]Spring multiple Opened Connections

I set up a new Spring Boot Application including only the spring-boot-starter-data-mongodb dependency and added basic mongodb configs (host, port, username, password, ..) in the application.properties.我设置了一个新的 Spring 引导应用程序,仅包括spring-boot-starter-data-mongodb依赖项,并在 application.properties 中添加了基本的 mongodb 配置(主机、端口、用户名、密码......)。
When I execute the application the following appears in the console:当我执行应用程序时,控制台中会出现以下内容:

2020-12-27 23:30:21.306  INFO 25230 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:86}] to localhost:27017
2020-12-27 23:30:21.306  INFO 25230 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:87}] to localhost:27017

I am curios why the connection was opened twice by spring.我很好奇为什么 spring 打开了两次连接。 Isn't one opened connection enough?一个打开的连接还不够吗?

Please add the below line into your properties file.请将以下行添加到您的属性文件中。

spring.data.mongodb.min-connections-per-host=1

The default size is 2 for the MongoDB java driver. MongoDB java 驱动程序的默认大小为 2。

Hope this will work for you!希望这对你有用!

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

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