mongo密码

This commit is contained in:
尹吉欢
2018-12-30 11:16:44 +08:00
parent 663390b271
commit fae953db27
@@ -1,5 +1,6 @@
package com.fangjia.job.youfang.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -17,6 +18,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
@Configuration
@@ -43,7 +45,9 @@ public class SpringMongoConfig {
@Primary
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
List<ServerAddress> seeds = Arrays.asList(new ServerAddress(youfangUrl, youfangPort));
List<ServerAddress> seeds = Arrays.asList(
new ServerAddress("mongo.db.fangjia.com", 28017),
new ServerAddress("secondary.mongo.db.fangjia.com", 28017));
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
int connPerHost = 10;
builder.connectionsPerHost(connPerHost);
@@ -54,7 +58,9 @@ public class SpringMongoConfig {
int timeOut = 10000;
builder.connectTimeout(timeOut);
MongoClientOptions options = builder.build();
MongoClient mongoClient = new MongoClient(seeds, options);
List<MongoCredential> cres = new ArrayList<>();
cres.add(MongoCredential.createCredential("developer", "admin", "G00IDCDEV12385".toCharArray()));
MongoClient mongoClient = new MongoClient(seeds, cres, options);
return new SimpleMongoDbFactory(mongoClient, youfangName);
}