springboot配置mongodb连接池

2023-01-13 08:48:26

请参考https://github.com/SpringForAll/spring-boot-starter-mongodb-plus/

spring-boot-starter-mongodb-plus

对官方spring boot starter对mongodb支持的扩展,提供更多配置属性,比如:连接数的配置等
如何使用

在使用了spring-boot-starter-data-mongodb的项目中,增加以下依赖


com.spring4all
mongodb-plus-spring-boot-starter
1.0.0.RELEASE

在应用主类上增加@EnableMongoPlus注解,比如:

@EnableMongoPlus
@SpringBootApplication
public class Application {

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

}

配置参数

可配置参数如下:

spring.data.mongodb.option.min-connection-per-host=0
spring.data.mongodb.option.max-connection-per-host=100
spring.data.mongodb.option.threads-allowed-to-block-for-connection-multiplier=5
spring.data.mongodb.option.server-selection-timeout=30000
spring.data.mongodb.option.max-wait-time=120000
spring.data.mongodb.option.max-connection-idle-time=0
spring.data.mongodb.option.max-connection-life-time=0
spring.data.mongodb.option.connect-timeout=10000
spring.data.mongodb.option.socket-timeout=0

spring.data.mongodb.option.socket-keep-alive=false
spring.data.mongodb.option.ssl-enabled=false
spring.data.mongodb.option.ssl-invalid-host-name-allowed=false
spring.data.mongodb.option.always-use-m-beans=false

spring.data.mongodb.option.heartbeat-socket-timeout=20000
spring.data.mongodb.option.heartbeat-connect-timeout=20000
spring.data.mongodb.option.min-heartbeat-frequency=500
spring.data.mongodb.option.heartbeat-frequency=10000
spring.data.mongodb.option.local-threshold=15

上述配置值均为默认值

参数解释请参照 https://blog.csdn.net/qazwsx081/article/details/50924352

  • 作者:一派从戎风度
  • 原文链接:https://blog.csdn.net/qq_35337467/article/details/81359342
    更新时间:2023-01-13 08:48:26