當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。