本文整理匯總了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());
}