当前位置: 首页>>代码示例>>Java>>正文


Java MongoDbFactory类代码示例

本文整理汇总了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;
}
 
开发者ID:ralscha,项目名称:eds-starter6-simple-mongodb,代码行数:20,代码来源:MongoConfig.java

示例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();
}
 
开发者ID:paulcwarren,项目名称:spring-content,代码行数:22,代码来源:HypermediaConfigurationTest.java

示例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"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:27,代码来源:MongoServiceConnectorCreatorTest.java

示例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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:37,代码来源:MongoServiceConnectorCreatorTest.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:GoogleAuthenticatorMongoDbConfiguration.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:MongoDbEventsConfiguration.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:11,代码来源:MongoDbMultifactorAuthenticationTrustConfiguration.java

示例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;
}
 
开发者ID:marrow16,项目名称:Nasapi,代码行数:11,代码来源:MongoContainer.java

示例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);
}
 
开发者ID:marrow16,项目名称:Nasapi,代码行数:15,代码来源:Nasapi.java

示例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();
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Cloud-Foundry-For-Developers,代码行数:12,代码来源:HomeController.java

示例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));
}
 
开发者ID:mikeqian,项目名称:house,代码行数:10,代码来源:AppConfig.java

示例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());
}
 
开发者ID:ImmobilienScout24,项目名称:switchman,代码行数:9,代码来源:Persistence.java


注:本文中的org.springframework.data.mongodb.MongoDbFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。