Simplify MongoDB Connection Settings with spring-boot-starter-mongodb-plus

This guide introduces the spring-boot-starter-mongodb-plus library, shows how to add it to a Spring Boot project, enables easy annotation-based activation, and provides a comprehensive list of configurable MongoDB connection properties with their default values for fine‑tuned backend performance.

Programmer DD
Programmer DD
Programmer DD
Simplify MongoDB Connection Settings with spring-boot-starter-mongodb-plus

Previously, configuring MongoDB connection options in Spring Boot required custom MongoDbFactory implementations, which could be cumbersome. The spring-boot-starter-mongodb-plus project, created on the spring4all GitHub, extends the official Spring Boot MongoDB starter to expose additional configuration properties such as connection pool size, timeouts, and SSL settings.

How to Use the Starter

Add the dependency to your pom.xml:

<dependency>
  <groupId>com.spring4all</groupId>
  <artifactId>mongodb-plus-spring-boot-starter</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>

Enable the starter in your main application class with the @EnableMongoPlus annotation:

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

Supported Configuration Parameters

The following spring.data.mongodb.option.* properties can be set in application.yml or application.properties. All values shown are the defaults.

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

All the above values are the library's default settings; you can override them as needed for your environment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendJavaConfigurationSpring BootMongoDBStarter
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.