yml下spring.data.mongodb
以前mysql等在spring.xxx下配置,现在springboot新版本(小编3.2.3)在spring.data.xxx下了,如下所示,mongodb的配置在spring.data.mongodb下:
连接池相关参数配置-源码分析
拼接在url后面,在自动配置mongodbTemplate时,会自动解析url
看源码org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,在spring-boot-autoconfigure.jar下
配置及效果参看
spring:
data:
mongodb:
field-naming-strategy: org.springframework.data.mapping.model.SnakeCaseFieldNamingStrategy
auto-index-creation: true
# 配置参数参考com.mongodb.ConnectionString
# waitqueuetimeoutms表示maxWaitTime
# maxidletimems 表示maxConnectionIdleTime
uri: "mongodb://localhost:27017/dev?\
serverselectiontimeoutms=1000\
&sockettimeoutms=1000\
&connecttimeoutms=1000\
&maxpoolsize=50\
&minpoolsize=10\
&waitqueuetimeoutms=1000\
&maxidletimems=20000\
&maxlifetimems=60000"
# replicaSetName:
debug效果如下:
可以看到mongoTemplate里面的相关参数已经生效了