@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
public class MongoConfig {
private static final Logger logger = LoggerFactory.getLogger(MongoConfig.class);
// 覆盖容器中默认的MongoDbFacotry Bean
@Bean
@Autowired
public MongoDbFactory mongoDbFactory(MongoSettingsProperties properties) {
// 客户端配置(连接数,副本集群验证)
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
builder.connectionsPerHost(properties.getMaxConnectionsPerHost());
builder.minConnectionsPerHost(properties.getMinConnectionsPerHost());
if (properties.getReplicaSet() != null) {
builder.requiredReplicaSetName(properties.getReplicaSet());
}
builder.threadsAllowedToBlockForConnectionMultiplier(
properties.getThreadsAllowedToBlockForConnectionMultiplier());
builder.serverSelectionTimeout(properties.getServerSelectionTimeout());
builder.maxWaitTime(properties.getMaxWaitTime());
builder.maxConnectionIdleTime(properties.g
mongodb线程池实现
于 2020-02-07 14:01:09 首次发布