How to configure MongoDB connection count in Spring Boot The author of this article mainly rewrote the construction of MongoDbFactory to complete, and the overall implementation process is quite complex. In this article, we will talk about how to implement more configuration customization of MongoDB more easily.
spring-boot-starter-mongodb-plus
I created this project on Spring4All’s Github a few weeks ago to extend the official Spring Boot Starter support for mongodb by providing more configuration properties such as connection count configuration.
Let’s see if it’s a lot easier to customize with this extension than before:
How to use
- In the use of the
spring-boot-starter-data-mongodb
Add the following dependencies to your project
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>mongodb-plus-spring-boot-starter</artifactId>
<version>1.0.0. RELEASE</version>
</dependency>
Copy the code
- Add to the application main class
@EnableMongoPlus
Notes, such as:
@EnableMongoPlus
@SpringBootApplication
public class Application {
public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Copy the code
Available configuration parameters
The parameters are as follows:
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
Copy the code
The preceding values are the default values
Afterword.
If you feel that the project is useful to you, welcome to give Star support: https://github.com/SpringForAll/spring-boot-starter-mongodb-plus/
Also welcome to follow my:
- Github: https://github.com/dyc87112/
- Blog: http://blog.didispace.com/
This paper first: http://blog.didispace.com/springbootmongodb-plus/