Set Mongo Timeout in Spring Boot

后端 未结 7 1124
失恋的感觉
失恋的感觉 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 11:00

    To follow your theme, this would be the best to answer your question. Looks like you would like to set a timeout in your application.properties file.

    In order to do so:

    Instead of

    spring.data.mongodb.host=myHost
    spring.data.mongodb.port=27017
    spring.data.mongodb.database=myDatabase
    
    spring.data.mongodb.username=myUser
    spring.data.mongodb.password=myPassword
    

    Try this

    spring.data.mongodb.uri=mongodb://myUser:myPassword@myHost:27017,myHost:27017/myDatabase?serverSelectionTimeoutMS=2000&connectTimeoutMS=2000
    spring.data.mongodb.database=myDatabase
    spring.data.mongo.repositories.enabled=true
    

    Modify time in milliseconds to desired time.

提交回复
热议问题