本文整理汇总了Java中org.springframework.data.mongodb.MongoDbFactory类的典型用法代码示例。如果您正苦于以下问题:Java MongoDbFactory类的具体用法?Java MongoDbFactory怎么用?Java MongoDbFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoDbFactory类属于org.springframework.data.mongodb包,在下文中一共展示了MongoDbFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mappingMongoConverter
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(MongoConverter.class)
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
MongoMappingContext context, BeanFactory beanFactory) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver,
context);
try {
mappingConverter
.setCustomConversions(beanFactory.getBean(CustomConversions.class));
}
catch (NoSuchBeanDefinitionException ex) {
// Ignore
}
return mappingConverter;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:MongoDataAutoConfiguration.java
示例2: mappingMongoConverter
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Bean
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
MongoMappingContext context, BeanFactory beanFactory) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver,
context);
// remove _class field
mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
try {
mappingConverter
.setCustomConversions(beanFactory.getBean(CustomConversions.class));
}
catch (NoSuchBeanDefinitionException ex) {
// Ignore
}
return mappingConverter;
}
示例3: mongoDbFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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: cloudMongoCreationNoConfig
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Test
public void cloudMongoCreationNoConfig() throws Exception {
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", TEST_HOST, TEST_PORT, TEST_USERNAME, TEST_PASSWORD, TEST_DB);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertNotNull(mongoDbFactory);
MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
assertNotNull(mongo);
MongoCredential credentials = mongo.getCredentialsList().get(0);
List<ServerAddress> addresses = extractServerAddresses(mongo);
assertEquals(1, addresses.size());
ServerAddress address = addresses.get(0);
assertEquals(serviceInfo.getHost(), address.getHost());
assertEquals(serviceInfo.getPort(), address.getPort());
assertEquals(serviceInfo.getUserName(), credentials.getUserName());
assertNotNull(credentials.getPassword());
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(serviceInfo.getDatabase(), ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
}
示例5: cloudMongoCreationWithMultipleHostsByUri
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Test
public void cloudMongoCreationWithMultipleHostsByUri() throws Exception {
String uri = String.format("%s://%s:%[email protected]%s:%s/%s", MONGODB_SCHEME, TEST_USERNAME, TEST_PASSWORD,
StringUtils.arrayToDelimitedString(TEST_HOSTS, ","), TEST_PORT, TEST_DB);
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", uri);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertNotNull(mongoDbFactory);
MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
assertNotNull(mongo);
List<ServerAddress> addresses = extractServerAddresses(mongo);
assertEquals(3, addresses.size());
MongoCredential credentials = mongo.getCredentialsList().get(0);
assertEquals(TEST_USERNAME, credentials.getUserName());
assertNotNull(credentials.getPassword());
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(TEST_DB, ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
ServerAddress address1 = addresses.get(0);
assertEquals(TEST_HOST, address1.getHost());
assertEquals(TEST_PORT_DEFAULT, address1.getPort());
ServerAddress address2 = addresses.get(1);
assertEquals(TEST_HOST_1, address2.getHost());
assertEquals(TEST_PORT_DEFAULT, address2.getPort());
ServerAddress address3 = addresses.get(2);
assertEquals(TEST_HOST_2, address3.getHost());
assertEquals(TEST_PORT, address3.getPort());
}
示例6: cloudScanWithAllTypesOfServices
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Test
public void cloudScanWithAllTypesOfServices() {
ApplicationContext testContext = getTestApplicationContext(createMysqlService("mysqlDb"),
createPostgresqlService("postDb"),
createMongoService("mongoDb"),
createRedisService("redisDb"),
createRabbitService("rabbit"));
assertNotNull("Getting service by id", testContext.getBean("mysqlDb"));
assertNotNull("Getting service by id and type", testContext.getBean("mysqlDb", DataSource.class));
assertNotNull("Getting service by id", testContext.getBean("postDb"));
assertNotNull("Getting service by id and type", testContext.getBean("postDb", DataSource.class));
assertNotNull("Getting service by id", testContext.getBean("mongoDb"));
assertNotNull("Getting service by id and type", testContext.getBean("mongoDb", MongoDbFactory.class));
assertNotNull("Getting service by id", testContext.getBean("redisDb"));
assertNotNull("Getting service by id and type", testContext.getBean("redisDb", RedisConnectionFactory.class));
assertNotNull("Getting service by id", testContext.getBean("rabbit"));
assertNotNull("Getting service by id and type", testContext.getBean("rabbit", ConnectionFactory.class));
}
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:24,代码来源:AbstractCloudConfigServiceScanTest.java
示例7: mongoDbGoogleAuthenticatorFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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);
}
}
示例8: mongoAuthNEventsDbFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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);
}
}
示例9: mongoMfaTrustedAuthnDbFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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);
}
}
示例10: MongoContainer
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
public MongoContainer(MongoClient mongoClient,
MongoTemplate template,
MongoDbFactory mongoDbFactory,
MongoMappingContext context,
Environment environment) {
this.mongoClient = mongoClient;
this.template = template;
this.mongoDbFactory = mongoDbFactory;
this.context = context;
}
示例11: mongoContainer
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
/**
* Create the Mongo container (used by scripts to access MongoDB)
* @param mongoClient - the MongoClient (from Spring)
* @param environment - the environment
* @return the MongoContainer
*/
@Bean
public MongoContainer mongoContainer(MongoClient mongoClient,
MongoTemplate template,
MongoDbFactory mongoDbFactory,
MongoMappingContext context,
Environment environment) {
return new MongoContainer(mongoClient, template, mongoDbFactory, context, environment);
}
示例12: toString
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
private String toString(MongoDbFactory mongoDbFactory) {
if (mongoDbFactory == null) {
return "<none>";
} else {
try {
return mongoDbFactory.getDb().getMongo().getAddress().toString();
} catch (Exception ex) {
return "<invalid address> " + mongoDbFactory.getDb().getMongo().toString();
}
}
}
示例13: mongoDbFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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));
}
示例14: gridFsTemplate
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public GridFsTemplate gridFsTemplate(MongoDbFactory mongoDbFactory,
MongoTemplate mongoTemplate) {
return new GridFsTemplate(
new GridFsMongoDbFactory(mongoDbFactory, this.properties),
mongoTemplate.getConverter());
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:MongoDataAutoConfiguration.java
示例15: mongoDbFactory
import org.springframework.data.mongodb.MongoDbFactory; //导入依赖的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());
}