本文整理汇总了Java中org.springframework.data.mongodb.core.SimpleMongoDbFactory类的典型用法代码示例。如果您正苦于以下问题:Java SimpleMongoDbFactory类的具体用法?Java SimpleMongoDbFactory怎么用?Java SimpleMongoDbFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleMongoDbFactory类属于org.springframework.data.mongodb.core包,在下文中一共展示了SimpleMongoDbFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
/** The mongodb ops. */
/* (non-Javadoc)
* @see co.aurasphere.botmill.core.datastore.adapter.DataAdapter#setup()
*/
public void setup() {
MongoCredential credential = MongoCredential.createCredential(
ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.username"),
ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"),
ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.password").toCharArray());
ServerAddress serverAddress = new ServerAddress(
ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.server"),
Integer.valueOf(ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.port")));
MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient, ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"));
MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory);
this.source = (MongoOperations) mongoTemplate;
}
示例2: getMongoTemplate
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
private MongoTemplate getMongoTemplate(String host, int port,
String authenticationDB,//TODO: is it redundant ?
String database,
String user, char[] password)
throws UnknownHostException {
return new MongoTemplate(
new SimpleMongoDbFactory(
new MongoClient(
new ServerAddress(host, port),
Collections.singletonList(
MongoCredential.createCredential(
user,
authenticationDB,
password
)
)
),
database
)
);
}
示例3: mongoDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Override
public MongoDbFactory mongoDbFactory() throws Exception {
if (System.getenv("spring_eg_content_mongo_host") != null) {
String host = System.getenv("spring_eg_content_mongo_host");
String port = System.getenv("spring_eg_content_mongo_port");
String username = System.getenv("spring_eg_content_mongo_username");
String password = System.getenv("spring_eg_content_mongo_password");
// Set credentials
MongoCredential credential = MongoCredential.createCredential(username, getDatabaseName(), password.toCharArray());
ServerAddress serverAddress = new ServerAddress(host, Integer.parseInt(port));
// Mongo Client
MongoClient mongoClient = new MongoClient(serverAddress,Arrays.asList(credential));
// Mongo DB Factory
return new SimpleMongoDbFactory(mongoClient, getDatabaseName());
}
return super.mongoDbFactory();
}
示例4: mongoDbGoogleAuthenticatorFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@RefreshScope
@Bean
public MongoDbFactory mongoDbGoogleAuthenticatorFactory() {
try {
final MultifactorAuthenticationProperties.GAuth.Mongodb mongo = casProperties.getAuthn().getMfa().getGauth().getMongodb();
return new SimpleMongoDbFactory(new MongoClientURI(mongo.getClientUri()));
} catch (final Exception e) {
throw new BeanCreationException(e.getMessage(), e);
}
}
示例5: mongoAuthNEventsDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@RefreshScope
@Bean
public MongoDbFactory mongoAuthNEventsDbFactory() {
try {
return new SimpleMongoDbFactory(new MongoClientURI(casProperties.getEvents().getMongodb().getClientUri()));
} catch (final Exception e) {
throw new BeanCreationException(e.getMessage(), e);
}
}
示例6: mongoMfaTrustedAuthnDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@RefreshScope
@Bean
public MongoDbFactory mongoMfaTrustedAuthnDbFactory() {
try {
return new SimpleMongoDbFactory(new MongoClientURI(
casProperties.getAuthn().getMfa().getTrusted().getMongodb().getClientUri()));
} catch (final Exception e) {
throw new BeanCreationException(e.getMessage(), e);
}
}
示例7: mongoDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
public
@Bean
MongoDbFactory mongoDbFactory() throws Exception {
Resource resource = new ClassPathResource("/runtime.properties");
Properties props = PropertiesLoaderUtils.loadProperties(resource);
String uriStr = props.getProperty("mongo.url.dev", "");
return new SimpleMongoDbFactory(new MongoClientURI(uriStr));
}
示例8: mongoDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
MongoClientURI uri = new MongoClientURI(mongoDbUrl);
mongo = new MongoClient(uri);
mongo.setReadPreference(ReadPreference.primary());
mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED);
return new SimpleMongoDbFactory(mongo, uri.getDatabase());
}
示例9: mongoDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Bean
public MongoDbFactory mongoDbFactory() {
try {
return new SimpleMongoDbFactory(new MongoClient(), "music");
} catch (UnknownHostException e) {
throw new RuntimeException("Error creating MongoDbFactory: " + e);
}
}
示例10: createMongoTemplate
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Bean(name = "mongoTemplate")
public MongoTemplate createMongoTemplate() throws UnknownHostException {
MongoClient mongoClient = new MongoClient(host, port);
//TODO Configure additional MongoDB mongoClient settings if needed
MongoDbFactory factory = new SimpleMongoDbFactory(mongoClient, database, new UserCredentials(username, password));
MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), new MongoMappingContext());
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
return new MongoTemplate(factory, converter);
}
示例11: mongoTemplate
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Bean
@ConditionalOnProperty(value = APPLICATION_DATA_TYPE, havingValue = APPLICATION_DATA_TYPE_MONGO)
@Autowired
public MongoTemplate mongoTemplate(MongoProperties properties,
@Value("${spring.data.mongodb.password}") String password) throws Exception {
MongoClient client = new MongoClient(new ServerAddress(
properties.getHost(), properties.getPort()));
MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(client, properties.getDatabase(),
new UserCredentials(properties.getUsername(), password));
return new MongoTemplate(mongoDbFactory);
}
示例12: mongoDbFactory
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
MongoCredential credential = MongoCredential.createMongoCRCredential("user1", "test", "password1".toCharArray());
MongoClient mongoClient;
if (propertyResolver.getProperty("mode").equalsIgnoreCase("cluster")){
List<ServerAddress> servers = mongo.getServerAddressList();
mongoClient = new MongoClient(servers, Arrays.asList(credential));
mongoClient.setReadPreference(ReadPreference.nearest());
mongoClient.getReplicaSetStatus();
return new SimpleMongoDbFactory(mongoClient, propertyResolver.getProperty("databaseName"));
} else {
return new SimpleMongoDbFactory(mongo, propertyResolver.getProperty("databaseName"));
}
}
示例13: createMongoTemplate
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Produces
@ApplicationScoped
public MongoOperations createMongoTemplate() throws UnknownHostException, MongoException {
MongoDbFactory factory = new SimpleMongoDbFactory(new MongoClient(), "dev");
return new MongoTemplate(factory);
}
示例14: setup
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception
{
mongo = new MongoTemplate(new SimpleMongoDbFactory(new MongoClient(), "yummynoodle"));
mongo.dropCollection("menu");
}
示例15: categoriesMongoTemplate
import org.springframework.data.mongodb.core.SimpleMongoDbFactory; //导入依赖的package包/类
public
@Bean
MongoTemplate categoriesMongoTemplate() throws Exception {
MongoClient client;
client = getMongoClientForCategoriesDatabase();
MongoDbFactory categoriesMongoDbFactory = new SimpleMongoDbFactory(client, database);
MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(categoriesMongoDbFactory),
new MongoMappingContext());
// remove _class
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
return new MongoTemplate(categoriesMongoDbFactory, converter);
}