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


Java SimpleMongoDbFactory类代码示例

本文整理汇总了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;
	}
 
开发者ID:BotMill,项目名称:botmill-core,代码行数:21,代码来源:MongoDBAdapter.java

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

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

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

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

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

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

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

示例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);
    }
}
 
开发者ID:pivotalservices,项目名称:concourse-spring-music,代码行数:9,代码来源:MongoLocalConfig.java

示例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);
}
 
开发者ID:mkopylec,项目名称:allegro-intellij-templates,代码行数:11,代码来源:$ Spring Data MongoDB Setup.java

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

示例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"));
    }    
}
 
开发者ID:thpham,项目名称:ithings-demo,代码行数:16,代码来源:MongoConfiguration.java

示例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);
}
 
开发者ID:cilf,项目名称:spring-data-mongodb-java-ee-7-primefaces-5,代码行数:8,代码来源:MongoTemplateProducer.java

示例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");
}
 
开发者ID:huangye177,项目名称:spring4probe,代码行数:8,代码来源:MenuItemMappingIntegrationTests.java

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


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