mongo密码
This commit is contained in:
+8
-2
@@ -1,5 +1,6 @@
|
|||||||
package com.fangjia.job.youfang.config;
|
package com.fangjia.job.youfang.config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
|||||||
|
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.MongoClientOptions;
|
import com.mongodb.MongoClientOptions;
|
||||||
|
import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -43,7 +45,9 @@ public class SpringMongoConfig {
|
|||||||
@Primary
|
@Primary
|
||||||
@Bean
|
@Bean
|
||||||
public MongoDbFactory mongoDbFactory() throws Exception {
|
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();
|
MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
|
||||||
int connPerHost = 10;
|
int connPerHost = 10;
|
||||||
builder.connectionsPerHost(connPerHost);
|
builder.connectionsPerHost(connPerHost);
|
||||||
@@ -54,7 +58,9 @@ public class SpringMongoConfig {
|
|||||||
int timeOut = 10000;
|
int timeOut = 10000;
|
||||||
builder.connectTimeout(timeOut);
|
builder.connectTimeout(timeOut);
|
||||||
MongoClientOptions options = builder.build();
|
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);
|
return new SimpleMongoDbFactory(mongoClient, youfangName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user