Set Mongo Timeout in Spring Boot

后端 未结 7 1172
失恋的感觉
失恋的感觉 2020-12-30 10:21

I am using spring boot web application which connects to mongo db which is working out of the box. I just use the following properties:

spring.data.mongodb.h         


        
7条回答
  •  感动是毒
    2020-12-30 10:53

    MongoClientOptions is a class which has the required properties.

    Programmatically If you have configured your MongoDB programmatically, then below is the code snippet to help you out.

    DB mongoDb;
    
    MongoClient mongoClient = new MongoClient(new ServerAddress(url, port), 
                                MongoClientOptions.builder()
                                .socketTimeout(3000)
                                .minHeartbeatFrequency(25)
                                .heartbeatSocketTimeout(3000)
                                .build());
    mongoDb = mongoClient.getDB(dbname);
    

    XML Configuration - Advanced

    
    
      
        
      
    
    
    

    Also refer here for complete documentation.

提交回复
热议问题